MediaWiki:Glossar.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
K |
K |
||
Zeile 1: | Zeile 1: | ||
// s.a. vorlage:glossareintrag | // s.a. vorlage:glossareintrag | ||
+ | |||
+ | newRules[8].style.display = 'none'; //Glossar | ||
var g = [], off; | var g = [], off; |
Version vom 4. Januar 2012, 16:45 Uhr
// s.a. vorlage:glossareintrag
newRules[8].style.display = 'none'; //Glossar
var g = [], off;
function setGlossar() {
var spans = document.getElementsByTagName('SPAN');
for (var i=0;i<spans.length;i++)
if (spans[i].className=='glossar2')
g[g.length] = spans[i];
for (var i=0;i<g.length;i++) {
g[i].onclick = showTooltip;
g[i].onmouseout = glossOFF;
g[i].onmouseover = clearOFF;
//g[i].id = 'hideG';
//Suchen und Finden
var parentG = g[i].parentNode.tagName == "LI" ?
g[i].parentNode.parentNode :
(g[i].parentNode.previousSibling.tagName == "H2" || g[i].parentNode.previousSibling.tagName == "H3") ?
g[i].parentNode.previousSibling :
g[i].parentNode;
var anker=parentG.insertBefore(document.createElement("A"),
parentG.firstChild);
anker.name=g[i].id||'';
g[i].id= '';
anker.id=anker.name;
if (String(location.href).indexOf('#')!=-1)
var suchtext = String(location.href).substring(String(location.href).indexOf('#')).replace(/#/,''); if (suchtext==anker.name&& suchtext.length>1) {
location.href=location.href;
g[i].style.backgroundColor = "#fffccc";
}
}
}
function hideTooltip() {
for (var i in g) g[i].id = '';
}
function showTooltip() {
// g_body ansprechen
var gBody=this.getElementsByTagName('SMALL')[1];
//Glossarweite berechnen
var em=this.parentNode.appendChild(document.createElement('div'));
em.style.width=150+"pt";
var gBodyOffsetWidth = em.offsetWidth;
var MinL= em.offsetLeft-10;
this.parentNode.removeChild(em);
//Positionierung
var gBodyLeft = (this.offsetWidth - gBodyOffsetWidth)/2;
var gBodyOffsetLeft = this.offsetLeft + gBodyLeft ;
var gBodyRight = gBodyOffsetLeft + gBodyOffsetWidth;
var MaxR = MinL+10+this.parentNode.offsetWidth+10;
if (gBodyOffsetLeft < MinL && this.parentNode.tagName == "P")
gBodyLeft = gBodyLeft + (MinL - gBodyOffsetLeft);
if (gBodyRight > MaxR && this.parentNode.offsetWidth > gBodyOffsetWidth )
gBodyLeft = gBodyLeft + (MaxR-gBodyRight);
gBody.style.left = gBodyLeft +"px";
// anknipsen, ausknipsen
if (this.id == 'showTooltip') hideTooltip();
else {hideTooltip(); this.id = 'showTooltip';}
}
function glossOFF() { off= window.setTimeout('hideTooltip()', 500); }
function clearOFF() { if (off!='undefined') window.clearTimeout(off); }
// Script starten
setGlossar();