User:Error/standard.js

/* From http://en.wikipedia.org/wiki/User:Korath/Spoiler.js * and http://en.wikipedia.org/wiki/Template_talk:Spoiler_top * Hides the text between spoiler begin and spoiler end. */

function hide_spoilerbox(num) { document.getElementById("spoilercontents_" + num).style.display="none"; var lk = document.getElementById("spoilerlk_" + num); lk.replaceChild(document.createTextNode("show"), lk.firstChild); lk.setAttribute("href", "javascript:show_spoilerbox(" + num + ")"); }

function show_spoilerbox(num) { document.getElementById("spoilercontents_" + num).style.display=""; var lk = document.getElementById("spoilerlk_" + num); lk.replaceChild(document.createTextNode("hide"), lk.firstChild); lk.setAttribute("href", "javascript:hide_spoilerbox(" + num + ")"); }

function setup_spoilerbox(initial) { var divs = document.getElementsByTagName("div"); var box; var contents; var lk; var txt; if (divs && document.getElementById) for (var x = 0; x < divs.length; ++x) if (divs[x].className.indexOf("spoilerbox") != -1) {	 box = divs[x].getElementsByTagName("table")[0].getElementsByTagName("tr"); contents = box[1]; contents.id = "spoilercontents_" + x;	 box = box[0].getElementsByTagName("td")[0].getElementsByTagName("div")[0]; var lk = document.createElement('a'); if (initial) {	     lk.setAttribute("href", "javascript:hide_spoilerbox(" + x + ")"); lk.appendChild(document.createTextNode("hide")); }	 else {	     lk.setAttribute("href", "javascript:show_spoilerbox(" + x + ")"); lk.appendChild(document.createTextNode("show")); contents.style.display="none"; }	 lk.id = "spoilerlk_" + x;	  box.appendChild(document.createTextNode(" [")); box.appendChild(lk); box.appendChild(document.createTextNode("]")); } }

function load_spoilerbox { // use setup_spoilerbox(false) instead to hide spoiler boxes by default setup_spoilerbox(true); }

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