MediaWiki:Glossar.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
K |
|||
Zeile 3: | Zeile 3: | ||
newRules[1].style.display = 'none'; //Glossar | newRules[1].style.display = 'none'; //Glossar | ||
− | var g = [], off; | + | var g = [], g2 = [], gSkt = [], gJap = [], glossar, off; |
function setGlossar() { | function setGlossar() { | ||
var spans = document.getElementsByTagName('SPAN'); | var spans = document.getElementsByTagName('SPAN'); | ||
− | for (var i=0;i<spans.length;i++) | + | // Arrays füllen |
− | if (spans[i].className=='glossar2') | + | for (var i=0;i<spans.length;i++) { |
+ | if (spans[i].className=='glossar2') { | ||
g[g.length] = spans[i]; | g[g.length] = spans[i]; | ||
− | for (var i | + | g2[g2.length] = spans[i].getElementsByTagName('SMALL')[1].cloneNode(true); |
+ | } | ||
+ | } | ||
+ | for (var i in g) { | ||
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'; | //g[i].id = 'hideG'; | ||
− | + | // Suchen und Finden | |
− | //Suchen und Finden | ||
var parentG = g[i].parentNode.tagName == "LI" ? | var parentG = g[i].parentNode.tagName == "LI" ? | ||
g[i].parentNode.parentNode : g[i].parentNode; | g[i].parentNode.parentNode : g[i].parentNode; | ||
Zeile 31: | Zeile 34: | ||
} | } | ||
} | } | ||
− | } | + | // 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.innerHTML = '<p>Fachvokabeln auf dieser Seite</p>'; | ||
+ | glossar = glossarFrame.appendChild(document.createElement('div')); | ||
+ | glossar.className = 'hide'; | ||
+ | glossar.onclick = showG; | ||
+ | function showG() {this.className = this.className == 'show' ? 'hide' : 'show'}; | ||
+ | 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) { | ||
+ | if (gSpans[x].className && gSpans[x].className == 'dvn') | ||
+ | g2[i].removeChild(gSpans[x]); | ||
+ | if (gSpans[x].className && gSpans[x].className == 'mehr' && gSpans[x].getElementsByTagName('A')[0]) { | ||
+ | gSpans[x].getElementsByTagName('A')[0].innerHTML='⇒'; | ||
+ | } | ||
+ | } | ||
+ | // Spans ordnen | ||
+ | for (var x in gSpans) { | ||
+ | if (gSpans[x].className && (gSpans[x].className == 'Romaji' || gSpans[x].className == 'skt')) { | ||
+ | var code = gSpans[x].firstChild ? | ||
+ | gSpans[x].firstChild.nodeValue || gSpans[x].firstChild.firstChild.nodeValue || '' : ''; | ||
+ | code = String(code).toLowerCase().replace(/[ōŌ]/g,'o').replace(/[ūŪ]/g,'u'); | ||
+ | code = code.replace(/[āĀ]/g,'a').replace(/<[^>]+>/g,'').replace(/[\s-]/g,''); | ||
+ | } | ||
+ | if (gSpans[x].className && gSpans[x].className == 'Romaji') | ||
+ | gJap[gJap.length] = [code, g2[i].cloneNode(true)]; | ||
+ | if (gSpans[x].className && gSpans[x].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() { | function hideTooltip() { | ||
− | + | for (var i in g) g[i].id = ''; | |
} | } | ||
Zeile 64: | Zeile 123: | ||
// Script starten | // Script starten | ||
− | + | setGlossar(); |
Version vom 10. Februar 2012, 22:38 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";
}
}
// 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.innerHTML = '<p>Fachvokabeln auf dieser Seite</p>';
glossar = glossarFrame.appendChild(document.createElement('div'));
glossar.className = 'hide';
glossar.onclick = showG;
function showG() {this.className = this.className == 'show' ? 'hide' : 'show'};
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) {
if (gSpans[x].className && gSpans[x].className == 'dvn')
g2[i].removeChild(gSpans[x]);
if (gSpans[x].className && gSpans[x].className == 'mehr' && gSpans[x].getElementsByTagName('A')[0]) {
gSpans[x].getElementsByTagName('A')[0].innerHTML='⇒';
}
}
// Spans ordnen
for (var x in gSpans) {
if (gSpans[x].className && (gSpans[x].className == 'Romaji' || gSpans[x].className == 'skt')) {
var code = gSpans[x].firstChild ?
gSpans[x].firstChild.nodeValue || gSpans[x].firstChild.firstChild.nodeValue || '' : '';
code = String(code).toLowerCase().replace(/[ōŌ]/g,'o').replace(/[ūŪ]/g,'u');
code = code.replace(/[āĀ]/g,'a').replace(/<[^>]+>/g,'').replace(/[\s-]/g,'');
}
if (gSpans[x].className && gSpans[x].className == 'Romaji')
gJap[gJap.length] = [code, g2[i].cloneNode(true)];
if (gSpans[x].className && gSpans[x].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();