User:Bawolff/onebox.js
From Wikinews, the free news source you can write!
Note: After saving, you may have to bypass your browser's cache to see the changes. Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac); IE: hold Ctrl while clicking Refresh, or press Ctrl-F5; Konqueror: simply click the Reload button, or press F5; Opera users may need to completely clear their cache in Tools→Preferences. — More skins
//This scrit makes it so you can only have one dynamic nav box open at a time //To use: /* ;Add <big>only the part directly below</big> to your [[special:mypage/monobook.js]] (or whatever skin you use): <pre> //Insert [[user:Bawolff/onebox.js]] - only allow one box open at a time var url = "http://en.wikinews.org/w/index.php?title=user:Bawolff/onebox.js&action=raw&ctype=text/javascript&dontcountme=s"; var scriptElem = document.createElement( 'script' ); scriptElem.setAttribute( 'src' , url ); scriptElem.setAttribute( 'type' , 'text/javascript' ); document.getElementsByTagName( 'head' )[0].appendChild( scriptElem ); </pre> ;Do not add the part under this line: ----- */ // ============================================================ // BEGIN Dynamic Navigation Bars (experimental) // set up the words in your language var LOCAL_NavigationBarHide = '[ you suck! ]'; var LOCAL_NavigationBarShow = '[ Give Me More! ]'; // set up max count of Navigation Bars on page, // if there are more, all will be hidden // NavigationBarShowDefault = 0; // all bars will be hidden // NavigationBarShowDefault = 1; // on pages with more than 1 bar all bars will be hidden var LOCAL_NavigationBarShowDefault = 1; // shows and hides content and picture (if available) of navigation bars // Parameters: // indexNavigationBar: the index of navigation bar to be toggled function LOCAL_toggleNavigationBar(LOCAL_indexNavigationBar) { var LOCAL_NavToggle = document.getElementById("NavToggle" + LOCAL_indexNavigationBar); var LOCAL_NavFrame = document.getElementById("NavFrame" + LOCAL_indexNavigationBar); if (!LOCAL_NavFrame || !LOCAL_NavToggle) { return false; } // if shown now if (LOCAL_NavToggle.firstChild.data == LOCAL_NavigationBarHide) { for ( var LOCAL_NavChild = LOCAL_NavFrame.firstChild; LOCAL_NavChild != null; LOCAL_NavChild = LOCAL_NavChild.nextSibling ) { if (LOCAL_NavChild.className == 'NavPic') { LOCAL_NavChild.style.display = 'none'; } if (LOCAL_NavChild.className == 'NavContent') { LOCAL_NavChild.style.display = 'none'; } } LOCAL_NavToggle.firstChild.data = LOCAL_NavigationBarShow; // if hidden now } else if (LOCAL_NavToggle.firstChild.data == LOCAL_NavigationBarShow) { //Start hiding all open boxes. things with f is loops to close everything for ( f = 1; f < 50; //prevent indef loop f++ ) { var LOCAL_f_NavToggle = document.getElementById("NavToggle" + f); var LOCAL_f_NavFrame = document.getElementById("NavFrame" + f); if (!LOCAL_f_NavFrame || !LOCAL_f_NavToggle) { break; } for ( var LOCAL_f_NavChild = LOCAL_f_NavFrame.firstChild; LOCAL_f_NavChild != null; LOCAL_f_NavChild = LOCAL_f_NavChild.nextSibling ) { if (LOCAL_f_NavChild.className == 'NavPic') { LOCAL_f_NavChild.style.display = 'none'; } if (LOCAL_f_NavChild.className == 'NavContent') { LOCAL_f_NavChild.style.display = 'none'; } } LOCAL_f_NavToggle.firstChild.data = LOCAL_NavigationBarShow; } //open selected one for ( var LOCAL_NavChild = LOCAL_NavFrame.firstChild; LOCAL_NavChild != null; LOCAL_NavChild = LOCAL_NavChild.nextSibling ) { if (LOCAL_NavChild.className == 'NavPic') { LOCAL_NavChild.style.display = 'block'; } if (LOCAL_NavChild.className == 'NavContent') { LOCAL_NavChild.style.display = 'block'; } } LOCAL_NavToggle.firstChild.data = LOCAL_NavigationBarHide; } } // adds show/hide-button to navigation bars function LOCAL_createNavigationBarToggleButton() { var LOCAL_indexNavigationBar = 0; // iterate over all < div >-elements for( var i=0; LOCAL_NavFrame = document.getElementsByTagName("div")[i]; i++ ) { // if found a navigation bar if (LOCAL_NavFrame.className == "NavFrame") { LOCAL_indexNavigationBar++; var LOCAL_NavToggle = document.createElement("a"); LOCAL_NavToggle.className = 'NavToggle'; LOCAL_NavToggle.setAttribute('id', 'NavToggle' + LOCAL_indexNavigationBar); LOCAL_NavToggle.setAttribute('href', 'javascript:LOCAL_toggleNavigationBar(' + LOCAL_indexNavigationBar + ');'); var LOCAL_NavToggleText = document.createTextNode(LOCAL_NavigationBarHide); LOCAL_NavToggle.appendChild(LOCAL_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 < LOCAL_NavFrame.childNodes.length; j++ ) { if (LOCAL_NavFrame.childNodes[j].className == "NavHead") { LOCAL_NavFrame.childNodes[j].appendChild(LOCAL_NavToggle); } } LOCAL_NavFrame.setAttribute('id', 'NavFrame' + LOCAL_indexNavigationBar); } } // if more Navigation Bars found than Default: hide all if (LOCAL_NavigationBarShowDefault < LOCAL_indexNavigationBar) { for( var i=1; i<=LOCAL_indexNavigationBar; i++ ) { LOCAL_toggleNavigationBar(i); } } } addLoadEvent(LOCAL_createNavigationBarToggleButton); // comment stuff : http://en.wikinews.org/w/index.php?title=User:Bawolff/monobook.js&oldid=403650
