MediaWiki:Glossar.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
Zeile 1: | Zeile 1: | ||
// s.a. vorlage:glossareintrag | // s.a. vorlage:glossareintrag | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
newRules[1].style.display = 'none'; //Glossar | newRules[1].style.display = 'none'; //Glossar | ||
Zeile 133: | Zeile 81: | ||
} | } | ||
} | } | ||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
if (gJap.length>0) { | if (gJap.length>0) { | ||
gJap.sort(); | gJap.sort(); |
Version vom 17. Februar 2012, 21:07 Uhr
// s.a. vorlage:glossareintrag
newRules[1].style.display = 'none'; //Glossar
var g = [], g2 = [], gSkt = [], gJap = [], glossar, off;
function setGlossar() {
var spans = document.getElementsByTagName('SPAN');
// Arrays füllen
for (var i=0;i<spans.length;i++) {
if (spans[i].className=='glossar2') {
g[g.length] = spans[i];
g2[g2.length] = spans[i].getElementsByTagName('SMALL')[1].cloneNode(true);
}
}
for (var i in g) {
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;
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 showG() {this.parentNode.className = this.parentNode.className == 'show' ? 'hide' : 'show'};
// Glossarliste erstellen
if (document.getElementById('catlinks') && g2.length > 0) {
document.getElementById('catlinks').style.display = 'none';
glossarFrame = document.getElementById('catlinks').parentNode.insertBefore(document.createElement('div'), document.getElementById('catlinks'));
glossarFrame.id = 'glossarSmall';
glossarFrame.className = 'hide';
glossarHead = glossarFrame.appendChild(document.createElement('div'));
glossarHead.id = 'glossarHead';
glossarHead.innerHTML = '<p>Fachvokabeln auf dieser Seite</p>';
glossarHead.onclick = showG;
glossar = glossarFrame.appendChild(document.createElement('div'));
glossar.id = 'glossarList';
for (var i in g2) {
//verdoppelungen ausschließen
for (z in g2)
if (g2[z].innerHTML && g2[z].innerHTML == g2[i].innerHTML && z != i )
g2.splice(z,1);
if (g2[i].innerHTML)
g2[i].innerHTML=g2[i].innerHTML.replace(/\({1}/, "").replace(/\)(?!.*\))/, "");
}
// Spans bearbeiten
for (var i in g2) {
gSpans=g2[i].getElementsByTagName('SPAN');
for (var x in gSpans) {
var spanX = (gSpans[x] && gSpans[x].className) ? gSpans[x] : 0;
if (spanX && spanX.className == 'dvn')
g2[i].removeChild(spanX);
if (spanX && spanX.className == 'mehr' && spanX.getElementsByTagName('A')[0]) {
spanX.getElementsByTagName('A')[0].innerHTML='⇒';
}
}
// Spans ordnen
for (var x in gSpans) {
var spanX = (gSpans[x] && gSpans[x].className) ? gSpans[x] : 0;
if (spanX && (spanX.className == 'Romaji' || spanX.className == 'skt')) {
var code = spanX.firstChild ?
spanX.firstChild.nodeValue || spanX.firstChild.firstChild.nodeValue || '' : '';
code = String(code).toLowerCase().replace(/[ōŌ]/g,'o').replace(/[ūŪ]/g,'u');
code = code.replace(/[āĀ]/g,'a').replace(/<[^>]+>/g,'').replace(/[\s-]/g,'');
}
if (spanX && spanX.className == 'Romaji')
gJap[gJap.length] = [code, g2[i].cloneNode(true)];
if (spanX && spanX.className == 'skt')
gSkt[gSkt.length] = [code, g2[i].cloneNode(true)];
}
}
if (gJap.length>0) {
gJap.sort();
for (var i in gJap)
glossar.appendChild(gJap[i][1]);
}
if (gSkt.length>0) {
gSkt.sort();
if (gJap.length>2)
glossar.innerHTML += '<p class=ueSkt>Sanskrit</p>';
for (var i in gSkt)
glossar.appendChild(gSkt[i][1]);
}
}
} // Ende Glossarliste
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();