Misplaced Pages

User:CesarB/monobook.js

Article snapshot taken from Wikipedia with creative commons attribution-sharealike license. Give it a read and then ask your questions in the chat. We can research this topic together.
< User:CesarB

This is an old revision of this page, as edited by CesarB (talk | contribs) at 16:49, 2 September 2006 (bug fix). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

Revision as of 16:49, 2 September 2006 by CesarB (talk | contribs) (bug fix)(diff) ← Previous revision | Latest revision (diff) | Newer revision → (diff)
Code that you insert on this page could contain malicious content capable of compromising your account. If you import a script from another page with "importScript", "mw.loader.load", "iusc", or "lusc", take note that this causes you to dynamically load a remote script, which could be changed by others. Editors are responsible for all edits and actions they perform, including by scripts. User scripts are not centrally supported and may malfunction or become inoperable due to software changes. A guide to help you find broken scripts is available. If you are unsure whether code you are adding to this page is safe, you can ask at the appropriate village pump.
This code will be executed when previewing this page.
The accompanying .css page for this skin is at User:CesarB/monobook.css.
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Misplaced Pages:Bypass your cache.
/*<pre><nowiki>*/

// Undo addLoadEvent(createNavigationBarToggleButton);

window.removeEventListener("load", createNavigationBarToggleButton, false);

// Replace function
 // adds show/hide-button to navigation bars
 function createNavigationBarToggleButton()
 {
    var indexNavigationBar = 0;
    var countDefaultNavigationBar = 0;
    var NavFrame;
    // iterate over all < div >-elements
    for(
            var i=0; 
            NavFrame = document.getElementsByTagName("div"); 
            i++
        ) {
        // if found a navigation bar
        if (NavFrame.className == "NavFrame" || NavFrame.className == "NavFrameDefaultShow" || NavFrame.className == "NavFrameDefaultHide") {
 
            indexNavigationBar++;
            if (NavFrame.className == "NavFrame")
                countDefaultNavigationBar++;
            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);
            // Find the NavHead and attach the toggle link (Must be this complicated because Moz's firstChild handling is borked)
            for(
              var j=0; 
              j < NavFrame.childNodes.length; 
              j++
            ) {
              if (NavFrame.childNodes.className == "NavHead") {
                NavFrame.childNodes.appendChild(NavToggle);
              }
            }
            NavFrame.setAttribute('id', 'NavFrame' + indexNavigationBar);
            if (NavFrame.className == "NavFrameDefaultHide")
                toggleNavigationBar(indexNavigationBar);
        }
    }
    // if more Navigation Bars found than Default: hide all
    if (NavigationBarShowDefault < countDefaultNavigationBar) {
        for(
                var i=1; 
                i<=indexNavigationBar; 
                i++
        ) {
            if (document.getElementById("NavFrame" + i).className == "NavFrame")
                toggleNavigationBar(i);
        }
    }
    // change all class names to NavFrame
    for(
            var i=1; 
            i<=indexNavigationBar; 
            i++
    ) {
        document.getElementById("NavFrame" + i).className = "NavFrame"
    }
 
 }

// Redo addLoadEvent(createNavigationBarToggleButton);
 addLoadEvent(createNavigationBarToggleButton);

/*</nowiki></pre>*/