Jump to content

User:Lupin/monobook.js

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by Lupin (talk | contribs) at 22:56, 22 September 2005. The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

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 Wikipedia:Bypass your cache.
// [[User:Lupin/popups.js]] - please include this line 

document.write('<script type="text/javascript" src="' 
             + 'http://en.wikipedia.org/w/index.php?title=User:Lupin/popups.js' 
             + '&action=raw&ctype=text/javascript&dontcountme=s"></script>');

function removeAccessKeys(keylist) {
  var t=document.getElementsByTagName('A'), u=document.getElementsByTagName('input');
  for (var i=0; i<t.length+u.length; ++i) {
    var s=((i<t.length) ? t[i] : u[i-t.length]);
    for (var j=0; j<keylist.length; ++j) if (s.accessKey==keylist[j]) s.accessKey='';
  }
};

function removeDeleteKey() {removeAccessKeys(['d']);}

if (window.addEventListener) window.addEventListener("load",removeDeleteKey,false);
else if (window.attachEvent) window.attachEvent("onload",removeDeleteKey);

function addOnloadFunction (f) {
  if (window.addEventListener) window.addEventListener("load",f,false);
  else if (window.attachEvent) window.attachEvent("onload",f);
};


////////////////////////////////////////////////////////////////
// Evaluator
// Source: http://krolik.net/js-eval.shtml

var evaluatorHTML='<FORM ID="Tester" NAME="Tester" onsubmit="return TesterExecute();" ><TEXTAREA NAME="MyCommand" COLS=60 ROWS=24 WRAP="off"></TEXTAREA><BR><INPUT TYPE=BUTTON value="Execute" onclick="TesterExecute();"><INPUT TYPE=BUTTON value="Show Object" onclick="ObjectDumpClicked();" ><BR><TEXTAREA NAME="MyResult" COLS=60 ROWS=35 WRAP="off"></TEXTAREA><BR></FORM>';

function ObjectDump(strObject) 
{
  var strOutput; 
  var vTemp; 
  var vAnotherTemp; 
  var vElement;
  vElement = eval(strObject); 
  strOutput = "typeof = " + typeof(vElement) + "\n\n";
  AppendOutput(strOutput);
  for (var x in vElement )  
  { 
   vTemp = strObject + "." + x.toString() ; 
   vAnotherTemp = strObject + "[" + x + "]" ; 
   strOutput = strOutput + vTemp + " = " + eval(vTemp) + "\n";
   AppendOutput(vTemp + " = " + eval(vTemp) + "\n");
  } 
  return strOutput ;  
 } 
 function AppendOutput(strText)
 {
  document.Tester.MyResult.value = document.Tester.MyResult.value + strText;
 }
 function Output(strText)
 {
  document.Tester.MyResult.value = strText;
 }
 function ObjectDumpClicked() 
 {
  document.Tester.MyResult.value="";
  ObjectDump(document.Tester.MyCommand.value); 
  return false;
 }
 function TesterExecute() 
 {       
  document.Tester.MyResult.value="";
  document.Tester.MyResult.value=eval(document.Tester.MyCommand.value); 
  return false;
 }

function addEvaluator() {
  var evalNode=document.createElement('div');
  evalNode.id='evalNode';
  evalNode.innerHTML=evaluatorHTML;
  document.body.appendChild(evalNode);
  document.Tester=document.getElementById('Tester');
}

addOnloadFunction(addEvaluator);

//
// end evaluator
////////////////////////////////////////////////////////////////



// ============================================================
// BEGIN Dynamic Navigation Bars

// set up the words in your language
var NavigationBarHide = 'Hide';
var NavigationBarShow = 'Show';

// 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
// I don't think this feature belongs in site-wide javascript, 
// and it wasn't trivial to do with my slightly approach. So it no longer does anything!
// it could be re-implemented without a great deal of trouble though


// we don't have nice classnames like the the organized folks in de do. 
// So we use a list of ids instead
var toolboxIds=RegExp('^p-(navigation|search|tb)$');

// 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(indexNavigationBar);
  
  if (!NavFrame || !NavToggle) {
    return false;
  }


  // affect all child nodes except these and silly ones without style attributes
  var nodenamesToAvoid=RegExp('^(A|H[1-9])$', 'i');

  // if shown now
  if (NavToggle.firstChild.data == NavigationBarHide) {
    for (var NavChild = NavFrame.firstChild; NavChild != null; NavChild = NavChild.nextSibling) {
      if (typeof NavChild.nodeName!= 'undefined' &&  
          typeof NavChild.style != 'undefined' && 
          !nodenamesToAvoid.test(NavChild.nodeName))
        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 (typeof NavChild.nodeName != 'undefined' && 
          typeof NavChild.style != 'undefined' && 
          !nodenamesToAvoid.test(NavChild.nodeName))
        NavChild.style.display = 'block';
      if (NavChild.className == 'NavToggle') {
        NavChild.firstChild.data = NavigationBarHide;
      }
    }
  }
}

// adds show/hide-button to navigation bars
function createNavigationBarToggleButton()
{
   // iterate over all < div >-elements
   var divElements=document.getElementsByTagName('div');

   for(
           var i=0; 
           NavFrame = divElements[i]; 
           i++
       ) {
       // if found a navigation bar
       if (toolboxIds.test(NavFrame.id)) {
           var NavToggle = document.createElement("a");
           NavToggle.className = 'NavToggle';
           NavToggle.setAttribute('href', "javascript:toggleNavigationBar('" + NavFrame.id + "');");

           var NavToggleText = document.createTextNode(NavigationBarHide);
           NavToggle.setAttribute('id', 'NavToggle' + NavFrame.id);
           NavToggle.appendChild(NavToggleText);

           // add NavToggle-Button as first div-element 
           // in < div class="NavFrame" >
           NavFrame.insertBefore(
               NavToggle,
               NavFrame.firstChild
           );
       }
   }
};


function addOnloadFunction_sitewide_monobook (f) {
  if (window.addEventListener) window.addEventListener("load",f,false);
  else if (window.attachEvent) window.attachEvent("onload",f);
};

addOnloadFunction_sitewide_monobook(createNavigationBarToggleButton);

// END Dynamic Navigation Bars
// ============================================================