Difference between revisions of "MediaWiki:Common.js"

From The Infosphere, the Futurama Wiki
Jump to navigation Jump to search
(Starting this javascript fun!)
 
(Hm, trying this then...)
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
/* Any JavaScript here will be loaded for all users on every page load. */
/*<pre>*/
/*<pre>*/
function toggleInfoDisplay(what) {
var reasonCaptionShow = "Show reason";
   var id = "c-" + what.id;
var reasonCaptionHide = "Hide reason";
   if(document.getElementById(id).style.display=="none") {
 
     document.getElementById(id).style.display = "block";
var hasClass = (function () {
     what.innerHTML = "Hide reason";
   var reCache = {};
  return function (element, className) {
    return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
  };
})();
 
function collapseReason(id) {
  var content = document.getElementById("reasonContent-" + id);
   var switch = document.getElementById("reasonSwitch-" + id)
  if(content.style.display=="none") {
     content.style.display = "block";
     switch.innerHTML = reasonCaptionHide;
   } else {
   } else {
     document.getElementById(id).style.display = "none";
     content.style.display = "none";
     what.innerHTML = "Show reason";
     switch.innerHTML = reasonCaptionShow;
   }
   }
}
}
function createAllReasonButtons() {
  var reasonIndex = 0;
  var divs = document.getElementsByTagName("div");
  for(var i = 0; i < divs.length; i++) {
    if(hasClass(divs[i], "reasonContainer") {
      var switch = divs[i].childNodes[0].childNodes[1];
      var content = divs[i].childNodes[1];
      content.setAttribute("id", "reasonContent-" + reasonIndex);
      var link = document.createElement("a");
      var linkCaption = document.createTextNode(reasonCaptionShow);
      link.setAttribute("id", "reasonSwitch-" + reasonIndex);
      link.setAttribute("href", "javascript:collapseReason(" + reasonIndex + ");");
      link.appendChild(linkCaption);
     
      switch.appendChild(link);
     
      reasonIndex++;
    }
  }
}
addOnloadHook(createAllReasonButtons);
/*</pre>*/
/*</pre>*/

Revision as of 00:31, 1 March 2008

/* Any JavaScript here will be loaded for all users on every page load. */
/*<pre>*/
var reasonCaptionShow = "Show reason";
var reasonCaptionHide = "Hide reason";

var hasClass = (function () {
  var reCache = {};
  return function (element, className) {
    return (reCache[className] ? reCache[className] : (reCache[className] = new RegExp("(?:\\s|^)" + className + "(?:\\s|$)"))).test(element.className);
  };
})();

function collapseReason(id) {
  var content = document.getElementById("reasonContent-" + id);
  var switch = document.getElementById("reasonSwitch-" + id)
  if(content.style.display=="none") {
    content.style.display = "block";
    switch.innerHTML = reasonCaptionHide;
  } else {
    content.style.display = "none";
    switch.innerHTML = reasonCaptionShow;
  }
}

function createAllReasonButtons() {
  var reasonIndex = 0;
  var divs = document.getElementsByTagName("div");
  for(var i = 0; i < divs.length; i++) {
    if(hasClass(divs[i], "reasonContainer") {
      var switch = divs[i].childNodes[0].childNodes[1];
      var content = divs[i].childNodes[1];

      content.setAttribute("id", "reasonContent-" + reasonIndex);

      var link = document.createElement("a");
      var linkCaption = document.createTextNode(reasonCaptionShow);
      link.setAttribute("id", "reasonSwitch-" + reasonIndex);
      link.setAttribute("href", "javascript:collapseReason(" + reasonIndex + ");");
      link.appendChild(linkCaption);
      
      switch.appendChild(link);
      
      reasonIndex++;
    }
  }
}

addOnloadHook(createAllReasonButtons);
/*</pre>*/