MediaWiki:Glossar.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
K |
|||
Zeile 8: | Zeile 8: | ||
if (spans[i].className=='glossar2') | if (spans[i].className=='glossar2') | ||
g[g.length] = spans[i]; | g[g.length] = spans[i]; | ||
− | for (var i | + | for (var i=0;i<g.length;i++) { |
g[i].onclick = showTooltip; | g[i].onclick = showTooltip; | ||
g[i].onmouseout = glossOFF; | g[i].onmouseout = glossOFF; | ||
g[i].onmouseover = clearOFF; | g[i].onmouseover = clearOFF; | ||
+ | //g[i].id = 'hideG'; | ||
//Suchen und Finden | //Suchen und Finden | ||
var parentG = g[i].parentNode.tagName == "LI" ? | var parentG = g[i].parentNode.tagName == "LI" ? | ||
Zeile 18: | Zeile 19: | ||
g[i].parentNode.previousSibling : | g[i].parentNode.previousSibling : | ||
g[i].parentNode; | g[i].parentNode; | ||
− | var anker=parentG.insertBefore(document.createElement("A"), parentG.firstChild); | + | var anker=parentG.insertBefore(document.createElement("A"), |
+ | parentG.firstChild); | ||
anker.name=g[i].id||''; | anker.name=g[i].id||''; | ||
− | g[i].id | + | g[i].id= ''; |
anker.id=anker.name; | anker.id=anker.name; | ||
if (String(location.href).indexOf('#')!=-1) | if (String(location.href).indexOf('#')!=-1) | ||
Zeile 29: | Zeile 31: | ||
} | } | ||
} | } | ||
− | function hideTooltip() { | + | function hideTooltip() { |
− | + | for (var i in g) g[i].id = ''; | |
− | |||
− | |||
} | } | ||
− | function showTooltip() { | + | function showTooltip() { |
// g_body ansprechen | // g_body ansprechen | ||
− | var gBody=this.getElementsByTagName(' | + | var gBody=this.getElementsByTagName('SMALL')[1]; |
− | |||
//Glossarweite berechnen | //Glossarweite berechnen | ||
var em=this.parentNode.appendChild(document.createElement('div')); | var em=this.parentNode.appendChild(document.createElement('div')); | ||
− | em.style.width= | + | em.style.width=150+"pt"; |
− | var gBodyOffsetWidth = em.offsetWidth | + | var gBodyOffsetWidth = em.offsetWidth; |
var MinL= em.offsetLeft-10; | var MinL= em.offsetLeft-10; | ||
this.parentNode.removeChild(em); | this.parentNode.removeChild(em); | ||
Zeile 56: | Zeile 55: | ||
gBodyLeft = gBodyLeft + (MaxR-gBodyRight); | gBodyLeft = gBodyLeft + (MaxR-gBodyRight); | ||
gBody.style.left = gBodyLeft +"px"; | gBody.style.left = gBodyLeft +"px"; | ||
− | |||
// anknipsen, ausknipsen | // anknipsen, ausknipsen | ||
if (this.id == 'showTooltip') hideTooltip(); | if (this.id == 'showTooltip') hideTooltip(); | ||
else {hideTooltip(); this.id = 'showTooltip';} | else {hideTooltip(); this.id = 'showTooltip';} | ||
} | } | ||
− | function glossOFF() { | + | function glossOFF() { off= window.setTimeout('hideTooltip()', 500); } |
− | function clearOFF() { if (off!='undefined') window.clearTimeout(off);} | + | function clearOFF() { if (off!='undefined') window.clearTimeout(off); } |
Version vom 26. Mai 2011, 21:01 Uhr
// s.a. vorlage:glossareintrag
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 = "#eef";
}
}
}
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)
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); }