Zeile 1: |
Zeile 1: |
| /* Das folgende JavaScript wird für alle Benutzer geladen. */ | | /* Das folgende JavaScript wird für alle Benutzer geladen. */ |
| | | |
− | //================================================================================ | + | // ============================================================ |
− | //*** Dynamic Navigation Bars | + | // BEGIN Enable multiple onload functions |
| | | |
− | // set up max count of Navigation Bars on page, | + | // setup onload functions this way: |
− | // if there are more, all will be hidden | + | // aOnloadFunctions[aOnloadFunctions.length] = function_name; // without brackets! |
− | // mw.user.options.set( 'NavigationBarShowDefault', 0 ); // all bars will be hidden
| |
− | // mw.user.options.set( 'NavigationBarShowDefault', 1 ); // on pages with more than 1 bar all bars will be hidden
| |
| | | |
− | // adds show/hide-button to navigation bars
| + | if (!window.aOnloadFunctions) { |
− | // using 'jquery.makeCollapsible': for messages
| + | var aOnloadFunctions = new Array(); |
− | // using 'user', 'mediawiki.user', 'user.options': wait for overrides in user.js
| + | } |
− | mw.loader.using( [ 'mediawiki.util', 'jquery.makeCollapsible', 'user', 'mediawiki.user', 'user.options' ], function() { $(function() {
| |
− | // allow setting NavigationBarShowDefault
| |
− | var showDefaultCount = mw.user.options.get( 'NavigationBarShowDefault',
| |
− | typeof NavigationBarShowDefault !== 'undefined' ? NavigationBarShowDefault : 1 );
| |
− | // allow user overrides for b/c
| |
− | var textHide = typeof NavigationBarHide === 'string' ? NavigationBarHide : mw.msg( 'collapsible-collapse' );
| |
− | var textShow = typeof NavigationBarShow === 'string' ? NavigationBarShow : mw.msg( 'collapsible-expand' );
| |
| | | |
− | // shows and hides content and picture (if available) of navigation bars
| + | window.onload = function() { |
− | // Parameters:
| + | if (window.aOnloadFunctions) { |
− | // indexNavigationBar: the index of navigation bar to be toggled
| + | for (var _i=0; _i<aOnloadFunctions.length; _i++) { |
− | function toggleNavigationBar(NavToggle, NavFrame)
| + | aOnloadFunctions[_i](); |
− | {
| + | } |
− | if (!NavFrame || !NavToggle) {
| + | } |
− | return false;
| + | } |
− | }
| |
| | | |
− | // if shown now
| + | // END Enable multiple onload functions |
− | if (NavToggle.firstChild.data === textHide) {
| + | // ============================================================ |
− | for (
| |
− | var NavChild = NavFrame.firstChild;
| |
− | NavChild !== null;
| |
− | NavChild = NavChild.nextSibling
| |
− | ) {
| |
− | if (NavChild.className === 'NavPic') {
| |
− | NavChild.style.display = 'none';
| |
− | }
| |
− | if (NavChild.className === 'NavContent') {
| |
− | NavChild.style.display = 'none';
| |
− | }
| |
− | if (NavChild.className === 'NavToggle') {
| |
− | NavChild.firstChild.data = textShow;
| |
− | }
| |
− | }
| |
| | | |
− | // if hidden now
| + | // ============================================================ |
− | } else if (NavToggle.firstChild.data === textShow) {
| + | // BEGIN Dynamic Navigation Bars |
− | for (
| + | // NEEDS Enable multiple onload functions |
− | var NavChild = NavFrame.firstChild;
| |
− | NavChild !== null;
| |
− | NavChild = NavChild.nextSibling
| |
− | ) {
| |
− | if (NavChild.className === 'NavPic') {
| |
− | NavChild.style.display = 'block';
| |
− | }
| |
− | if (NavChild.className === 'NavContent') {
| |
− | NavChild.style.display = 'block';
| |
− | }
| |
− | if (NavChild.className === 'NavToggle') {
| |
− | NavChild.firstChild.data = textHide;
| |
− | }
| |
− | }
| |
− | }
| |
− | }
| |
| | | |
− | function toggleNavigationBarFunction(NavToggle, NavFrame) {
| + | // set up the words in your language |
− | return function() {
| + | var NavigationBarHide = 'Einklappen'; |
− | toggleNavigationBar(NavToggle, NavFrame);
| + | var NavigationBarShow = 'Ausklappen'; |
− | return false;
| |
− | };
| |
− | }
| |
− | // iterate over all NavFrames
| |
− | var NavFrames = mw.util.$content.find( 'div.NavFrame' );
| |
| | | |
− | // if more Navigation Bars found and not template namespace than Default: hide all
| + | // set up max count of Navigation Bars on page, |
− | var initiallyToggle = showDefaultCount < NavFrames.length && mw.config.get( 'wgNamespaceNumber' ) !== 10;
| + | // if there are more, all will be hidden |
− | for (var i=0; i<NavFrames.length; i++) {
| + | // NavigationBarShowDefault = 0; // all bars will be hidden |
− | var NavFrame = NavFrames[i];
| + | // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden |
− | var NavToggle = document.createElement("a");
| + | if (typeof NavigationBarShowDefault == 'undefined' ) { |
− | NavToggle.className = 'NavToggle';
| + | var NavigationBarShowDefault = 1; |
− | NavToggle.setAttribute('href', '#');
| + | } |
| | | |
− | var NavToggleText = document.createTextNode(textHide);
| + | // shows and hides content and picture (if available) of navigation bars |
− | NavToggle.appendChild(NavToggleText);
| + | // Parameters: |
| + | // indexNavigationBar: the index of navigation bar to be toggled |
| + | function toggleNavigationBar(indexNavigationBar) |
| + | { |
| + | var NavToggle = document.getElementById("NavToggle" + indexNavigationBar); |
| + | var NavFrame = document.getElementById("NavFrame" + indexNavigationBar); |
| | | |
− | // add NavToggle-Button as first div-element
| + | if (!NavFrame || !NavToggle) { |
− | // in < div class="NavFrame" >
| + | return false; |
− | NavFrame.insertBefore(NavToggle, NavFrame.firstChild);
| + | } |
| | | |
− | NavToggle.onclick = toggleNavigationBarFunction(NavToggle, NavFrame);
| + | // if shown now |
− | if (initiallyToggle) {
| + | if (NavToggle.firstChild.data == NavigationBarHide) { |
− | toggleNavigationBar(NavToggle, NavFrame);
| + | for ( |
− | }
| + | var NavChild = NavFrame.firstChild; |
− | }
| + | NavChild != null; |
− | })}); | + | NavChild = NavChild.nextSibling |
| + | ) { |
| + | if (NavChild.className == 'NavPic') { |
| + | NavChild.style.display = 'none'; |
| + | } |
| + | if (NavChild.className == 'NavContent') { |
| + | NavChild.style.display = 'none'; |
| + | } |
| + | if (NavChild.className == 'NavToggle') { |
| + | NavChild.firstChild.data = NavigationBarShow; |
| + | } |
| + | } |
| | | |
− | //================================================================================ | + | // if hidden now |
| + | } else if (NavToggle.firstChild.data == NavigationBarShow) { |
| + | for ( |
| + | var NavChild = NavFrame.firstChild; |
| + | NavChild != null; |
| + | NavChild = NavChild.nextSibling |
| + | ) { |
| + | if (NavChild.className == 'NavPic') { |
| + | NavChild.style.display = 'block'; |
| + | } |
| + | if (NavChild.className == 'NavContent') { |
| + | NavChild.style.display = 'block'; |
| + | } |
| + | if (NavChild.className == 'NavToggle') { |
| + | NavChild.firstChild.data = NavigationBarHide; |
| + | } |
| + | } |
| + | } |
| + | } |
| + | |
| + | // adds show/hide-button to navigation bars |
| + | function createNavigationBarToggleButton() |
| + | { |
| + | var indexNavigationBar = 0; |
| + | // iterate over all < div >-elements |
| + | for( |
| + | var i=0; |
| + | NavFrame = document.getElementsByTagName("div")[i]; |
| + | i++ |
| + | ) { |
| + | // if found a navigation bar |
| + | if (NavFrame.className == "NavFrame") { |
| + | |
| + | indexNavigationBar++; |
| + | var NavToggle = document.createElement("a"); |
| + | NavToggle.className = 'NavToggle'; |
| + | NavToggle.setAttribute('id', 'NavToggle' + indexNavigationBar); |
| + | NavToggle.setAttribute('href', 'javascript:toggleNavigationBar(' + indexNavigationBar + ');'); |
| + | |
| + | var NavToggleText = document.createTextNode(NavigationBarHide); |
| + | NavToggle.appendChild(NavToggleText); |
| + | |
| + | // add NavToggle-Button as first div-element |
| + | // in < div class="NavFrame" > |
| + | NavFrame.insertBefore( |
| + | NavToggle, |
| + | NavFrame.firstChild |
| + | ); |
| + | NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar); |
| + | } |
| + | } |
| + | // if more Navigation Bars found than Default: hide all |
| + | if (NavigationBarShowDefault < indexNavigationBar) { |
| + | for( |
| + | var i=1; |
| + | i<=indexNavigationBar; |
| + | i++ |
| + | ) { |
| + | toggleNavigationBar(i); |
| + | } |
| + | } |
| + | |
| + | } |
| + | |
| + | aOnloadFunctions[aOnloadFunctions.length] = createNavigationBarToggleButton; |
| + | |
| + | // END Dynamic Navigation Bars |
| + | // ============================================================ |