Zum Inhalt springen
MediaWiki:Common.js: Unterschied zwischen den Versionen
Zur Navigation springen
Zur Suche springen
TiKu (Diskussion | Beiträge) (CSS-Änderungen) |
TiKu (Diskussion | Beiträge) (Code Style angepasst) |
||
Zeile 3: | Zeile 3: | ||
// ============================================================ | // ============================================================ | ||
// BEGIN Event Hooking | // BEGIN Event Hooking | ||
− | function | + | function HookEvent(hookName, hookFunction) |
{ | { | ||
if(window.addEventListener) { | if(window.addEventListener) { | ||
− | window.addEventListener(hookName, | + | window.addEventListener(hookName, hookFunction, false); |
} else if(window.attachEvent) { | } else if(window.attachEvent) { | ||
− | window.attachEvent("on" + hookName, | + | window.attachEvent("on" + hookName, hookFunction); |
} | } | ||
} | } | ||
Zeile 17: | Zeile 17: | ||
// BEGIN Dynamic Navigation Bars | // BEGIN Dynamic Navigation Bars | ||
− | + | var strNavigationBarHide = "Einklappen"; | |
− | var | + | var strNavigationBarShow = "Ausklappen"; |
− | var | ||
− | + | var navigationBarShowDefault = 0; | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
// shows and hides content and picture (if available) of navigation bars | // shows and hides content and picture (if available) of navigation bars | ||
// Parameters: | // Parameters: | ||
// indexNavigationBar: the index of navigation bar to be toggled | // indexNavigationBar: the index of navigation bar to be toggled | ||
− | function | + | function ToggleNavigationBar(indexNavigationBar) |
{ | { | ||
− | var | + | var naviToggle = document.getElementById("dcw_navitoggle" + indexNavigationBar); |
− | var | + | var naviFrame = document.getElementById("dcw_naviframe" + indexNavigationBar); |
− | if(! | + | if(!naviFrame || !naviToggle) { |
return false; | return false; | ||
} | } | ||
// if shown now | // if shown now | ||
− | if( | + | if(naviToggle.firstChild.data == strNavigationBarHide) { |
− | for(var | + | for(var naviChild = naviFrame.firstChild; naviChild != null; naviChild = naviChild.nextSibling) { |
− | if( | + | if(naviChild.className == "dcw_navipicture") { |
− | + | naviChild.style.display = "none"; | |
} | } | ||
− | if( | + | if(naviChild.className == "dcw_navicontent") { |
− | + | naviChild.style.display = "none"; | |
} | } | ||
− | if( | + | if(naviChild.className == "dcw_navitoggle") { |
− | + | naviChild.firstChild.data = strNavigationBarShow; | |
} | } | ||
} | } | ||
// if hidden now | // if hidden now | ||
− | } else if( | + | } else if(naviToggle.firstChild.data == strNavigationBarShow) { |
− | for(var | + | for(var naviChild = naviFrame.firstChild; naviChild != null; naviChild = naviChild.nextSibling) { |
− | if( | + | if(naviChild.className == "dcw_navipicture") { |
− | + | naviChild.style.display = "block"; | |
} | } | ||
− | if( | + | if(naviChild.className == "dcw_navicontent") { |
− | + | naviChild.style.display = "block"; | |
} | } | ||
− | if( | + | if(naviChild.className == "dcw_navitoggle") { |
− | + | naviChild.firstChild.data = strNavigationBarHide; | |
} | } | ||
} | } | ||
Zeile 72: | Zeile 65: | ||
// adds show/hide-button to navigation bars | // adds show/hide-button to navigation bars | ||
− | function | + | function CreateNavigationBarToggleButton() |
{ | { | ||
var indexNavigationBar = 0; | var indexNavigationBar = 0; | ||
− | // iterate over all < div >-elements | + | // iterate over all <div>-elements |
− | for(var i = 0; | + | for(var i = 0; naviFrame = document.getElementsByTagName("div")[i]; ++i) { |
// if found a navigation bar | // if found a navigation bar | ||
− | if( | + | if(naviFrame.className == "dcw_naviframe") { |
++indexNavigationBar; | ++indexNavigationBar; | ||
− | var | + | var naviToggle = document.createElement("a"); |
− | + | naviToggle.className = "dcw_navitoggle"; | |
− | + | naviToggle.setAttribute("id", "dcw_navitoggle" + indexNavigationBar); | |
− | NavToggle.setAttribute( | + | NavToggle.setAttribute("href", "javascript:ToggleNavigationBar(" + indexNavigationBar + ");"); |
− | var | + | var naviToggleText = document.createTextNode(strNavigationBarHide); |
− | + | naviToggle.appendChild(naviToggleText); | |
− | // add | + | // add naviToggle-Button as first div-element |
− | // in < div class="dcw_naviframe" > | + | // in <div class="dcw_naviframe"> |
− | + | naviFrame.insertBefore(naviToggle, naviFrame.firstChild); | |
− | + | naviFrame.setAttribute("id", "dcw_naviframe" + indexNavigationBar); | |
} | } | ||
} | } | ||
− | // if more | + | // if more navigation bars found than default: hide all |
− | if( | + | if(navigationBarShowDefault < indexNavigationBar) { |
for(var i = 1; i <= indexNavigationBar; ++i) { | for(var i = 1; i <= indexNavigationBar; ++i) { | ||
− | + | ToggleNavigationBar(i); | |
} | } | ||
} | } | ||
} | } | ||
− | + | HookEvent("load", CreateNavigationBarToggleButton); | |
// END Dynamic Navigation Bars | // END Dynamic Navigation Bars | ||
// ============================================================ | // ============================================================ |
Version vom 27. Juni 2007, 12:33 Uhr
/* Jedes JavaScript hier wird für alle Benutzer für jede Seite geladen. */ // ============================================================ // BEGIN Event Hooking function HookEvent(hookName, hookFunction) { if(window.addEventListener) { window.addEventListener(hookName, hookFunction, false); } else if(window.attachEvent) { window.attachEvent("on" + hookName, hookFunction); } } // END Event Hooking // ============================================================ // ============================================================ // BEGIN Dynamic Navigation Bars var strNavigationBarHide = "Einklappen"; var strNavigationBarShow = "Ausklappen"; var navigationBarShowDefault = 0; // shows and hides content and picture (if available) of navigation bars // Parameters: // indexNavigationBar: the index of navigation bar to be toggled function ToggleNavigationBar(indexNavigationBar) { var naviToggle = document.getElementById("dcw_navitoggle" + indexNavigationBar); var naviFrame = document.getElementById("dcw_naviframe" + indexNavigationBar); if(!naviFrame || !naviToggle) { return false; } // if shown now if(naviToggle.firstChild.data == strNavigationBarHide) { for(var naviChild = naviFrame.firstChild; naviChild != null; naviChild = naviChild.nextSibling) { if(naviChild.className == "dcw_navipicture") { naviChild.style.display = "none"; } if(naviChild.className == "dcw_navicontent") { naviChild.style.display = "none"; } if(naviChild.className == "dcw_navitoggle") { naviChild.firstChild.data = strNavigationBarShow; } } // if hidden now } else if(naviToggle.firstChild.data == strNavigationBarShow) { for(var naviChild = naviFrame.firstChild; naviChild != null; naviChild = naviChild.nextSibling) { if(naviChild.className == "dcw_navipicture") { naviChild.style.display = "block"; } if(naviChild.className == "dcw_navicontent") { naviChild.style.display = "block"; } if(naviChild.className == "dcw_navitoggle") { naviChild.firstChild.data = strNavigationBarHide; } } } } // adds show/hide-button to navigation bars function CreateNavigationBarToggleButton() { var indexNavigationBar = 0; // iterate over all <div>-elements for(var i = 0; naviFrame = document.getElementsByTagName("div")[i]; ++i) { // if found a navigation bar if(naviFrame.className == "dcw_naviframe") { ++indexNavigationBar; var naviToggle = document.createElement("a"); naviToggle.className = "dcw_navitoggle"; naviToggle.setAttribute("id", "dcw_navitoggle" + indexNavigationBar); NavToggle.setAttribute("href", "javascript:ToggleNavigationBar(" + indexNavigationBar + ");"); var naviToggleText = document.createTextNode(strNavigationBarHide); naviToggle.appendChild(naviToggleText); // add naviToggle-Button as first div-element // in <div class="dcw_naviframe"> naviFrame.insertBefore(naviToggle, naviFrame.firstChild); naviFrame.setAttribute("id", "dcw_naviframe" + indexNavigationBar); } } // if more navigation bars found than default: hide all if(navigationBarShowDefault < indexNavigationBar) { for(var i = 1; i <= indexNavigationBar; ++i) { ToggleNavigationBar(i); } } } HookEvent("load", CreateNavigationBarToggleButton); // END Dynamic Navigation Bars // ============================================================