User:Matasg/script.js

From Wikimedia Incubator

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Internet Explorer / Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5
  • Opera: Press Ctrl-F5.
/*Script from http://en.wikinews.org/wiki/Common.js
/* Any JavaScript here will be loaded for all users on every page load. Some other stuff is located at [[mediawiki:monobook.js]]
*/
function addLoadEvent(func) 
{
  if (window.addEventListener) 
    window.addEventListener("load", func, false);
  else if (window.attachEvent) 
    window.attachEvent("onload", func);
}
/*
==Dynamic nav - one box==
;Makes some dynamic nav boxes auto-close. See [[user:Bawolff/onebox-select.js]] & [[Template:Dynamic navigation noncentered]]
*Tested in MSIE 6, Opera 9.01, and firefox (1.5.0.11 and 2.0.0.something(I think its a 2 at the end)
*Adapted from the dynamic nav box script which is from somewhere on wikipedia
*/
// set up the words in your language
var ONCE_NavigationBarHide = '[ ↑ ]';
var ONCE_NavigationBarShow = '[ ↓ ]';
 
// 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 ONCE_NavigationBarShowDefault = 1;
 
 
// shows and hides content and picture (if available) of navigation bars
// Parameters:
//     indexNavigationBar: the index of navigation bar to be toggled
function ONCE_toggleNavigationBar(ONCE_indexNavigationBar)
{
   var ONCE_NavToggle = document.getElementById("NavToggleOnce" + ONCE_indexNavigationBar);
   var ONCE_NavFrame = document.getElementById("NavFrameOnce" + ONCE_indexNavigationBar);
 
   if (!ONCE_NavFrame || !ONCE_NavToggle) {
       return false;
   }
 
   // if shown now
   if (ONCE_NavToggle.firstChild.data == ONCE_NavigationBarHide) {
       for (
               var ONCE_NavChild = ONCE_NavFrame.firstChild;
               ONCE_NavChild != null;
               ONCE_NavChild = ONCE_NavChild.nextSibling
           ) {
           if (ONCE_NavChild.className == 'NavPic') {
               ONCE_NavChild.style.display = 'none';
           }
           if (ONCE_NavChild.className == 'NavContent') {
               ONCE_NavChild.style.display = 'none';
           }
       }
   ONCE_NavToggle.firstChild.data = ONCE_NavigationBarShow;
 
   // if hidden now
   } else if (ONCE_NavToggle.firstChild.data == ONCE_NavigationBarShow) {
//Start hiding all open boxes. things with f is loops to close everything
       for (
               f = 1;
               f < 50; //prevent indef loop
               f++
            )  {
                  var ONCE_f_NavToggle = document.getElementById("NavToggleOnce" + f);
                  var ONCE_f_NavFrame = document.getElementById("NavFrameOnce" + f);
 
                  if (!ONCE_f_NavFrame || !ONCE_f_NavToggle) {
                     break;
                  }
                  for (
                     var ONCE_f_NavChild = ONCE_f_NavFrame.firstChild;
                     ONCE_f_NavChild != null;
                     ONCE_f_NavChild = ONCE_f_NavChild.nextSibling
                      ) {
                           if (ONCE_f_NavChild.className == 'NavPic') {
                              ONCE_f_NavChild.style.display = 'none';
                           }
                           if (ONCE_f_NavChild.className == 'NavContent') {
                              ONCE_f_NavChild.style.display = 'none';
                           }
                        }
                 ONCE_f_NavToggle.firstChild.data = ONCE_NavigationBarShow; 
              }
 
//open selected one
 
       for (
               var ONCE_NavChild = ONCE_NavFrame.firstChild;
               ONCE_NavChild != null;
               ONCE_NavChild = ONCE_NavChild.nextSibling
           ) {
           if (ONCE_NavChild.className == 'NavPic') {
               ONCE_NavChild.style.display = 'block';
           }
           if (ONCE_NavChild.className == 'NavContent') {
               ONCE_NavChild.style.display = 'block';
           }
       }
   ONCE_NavToggle.firstChild.data = ONCE_NavigationBarHide;
   }
}
 
// adds show/hide-button to navigation bars
function ONCE_createNavigationBarToggleButton()
{
 
   var ONCE_indexNavigationBar = 0;
   // iterate over all < div >-elements
   for(
           var i=0; 
           ONCE_NavFrame = document.getElementsByTagName("div")[i]; 
           i++
       ) {
       // if found a navigation bar
       if (ONCE_NavFrame.className == "NavFrame NavOnce") {
 
           ONCE_indexNavigationBar++;
           var ONCE_NavToggle = document.createElement("a");
           ONCE_NavToggle.className = 'NavToggle';
           ONCE_NavToggle.setAttribute('id', 'NavToggleOnce' + ONCE_indexNavigationBar);
           ONCE_NavToggle.setAttribute('href', 'javascript:ONCE_toggleNavigationBar(' + ONCE_indexNavigationBar + ');');
 
           var ONCE_NavToggleText = document.createTextNode(ONCE_NavigationBarHide);
           ONCE_NavToggle.appendChild(ONCE_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 < ONCE_NavFrame.childNodes.length; 
             j++
           ) {
             if (ONCE_NavFrame.childNodes[j].className == "NavHead") {
               ONCE_NavFrame.childNodes[j].appendChild(ONCE_NavToggle);
             }
           }
           ONCE_NavFrame.setAttribute('id', 'NavFrameOnce' + ONCE_indexNavigationBar);
       }
   }
   // if more Navigation Bars found than Default: hide all
   if (ONCE_NavigationBarShowDefault < ONCE_indexNavigationBar) {
       for(
               var i=1; 
               i<=ONCE_indexNavigationBar; 
               i++
       ) {
           ONCE_toggleNavigationBar(i);
       }
   }
 
}
 
addLoadEvent(ONCE_createNavigationBarToggleButton);
 
/*
;RSS Feed insert. Only latest news. Should we add others?
*/
document.write('<link type="application/rss+xml" href="http://feeds.feedburner.com/WikinewsLatestNews" rel="alternate" title="Lastest News (RSS)" \/>')
/*
 
==Dynamic Nav (no-autoclose)==
*/
 
 // ============================================================
 // '''BEGIN Dynamic Navigation Bars (experimental)'''
 
 // set up the words in your language
 var NavigationBarHide = '[ - ]';
 var NavigationBarShow = '[ + ]';
 
 // 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 NavigationBarShowDefault = 1;
 
 
 // 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 NavToggle = document.getElementById("NavToggle" + indexNavigationBar);
    var NavFrame = document.getElementById("NavFrame" + indexNavigationBar);
 
    if (!NavFrame || !NavToggle) {
        return false;
    }
 
    // if shown now
    if (NavToggle.firstChild.data == NavigationBarHide) {
        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';
            }
        }
    NavToggle.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';
            }
        }
    NavToggle.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);
            // 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[j].className == "NavHead") {
                NavFrame.childNodes[j].appendChild(NavToggle);
              }
            }
            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);
        }
    }
 
 }
 
 addLoadEvent(createNavigationBarToggleButton);
 
 // END Dynamic Navigation Bars
 // ============================================================
 
 
/*