Misplaced Pages

User:CesarB/monobook.js: Difference between revisions

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 Browse history interactively← Previous editNext edit →Content deleted Content added
Revision as of 16:29, 2 September 2006 view sourceCesarB (talk | contribs)Administrators14,429 edits experimental defaulting for NavFrame: force class name to NavFrame← Previous edit Revision as of 16:49, 2 September 2006 view source CesarB (talk | contribs)Administrators14,429 edits bug fixNext edit →
Line 11: Line 11:
var indexNavigationBar = 0; var indexNavigationBar = 0;
var countDefaultNavigationBar = 0; var countDefaultNavigationBar = 0;
var NavFrame;
// iterate over all < div >-elements // iterate over all < div >-elements
for( for(

Revision as of 16:49, 2 September 2006

/*<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>*/