User:Tierrie/global.js

var showSpoiler = new Array;

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 showSpoilers(splrType) { var Divs= document.getElementsByTagName("div"); for (i=0;i<Divs.length;i++) { if (hasClass(Divs[i], 'splr_'+splrType)) { Divs[i].childNodes[1].style.display = 'none'; Divs[i].parentNode.nextSibling.style.display = 'block'; } }  document.cookie='showspoiler_'+splrType+'=1'; }

function hideSpoilers(splrType) { var Divs= document.getElementsByTagName("div"); for (i=0;i<Divs.length;i++) { if (hasClass(Divs[i], 'splr_'+splrType)) { Divs[i].childNodes[1].style.display = 'block'; Divs[i].parentNode.nextSibling.style.display = 'none'; } }  document.cookie='showspoiler_'+splrType+'=0'; }

function toggleSpoilers(ev) { var splrType=this.childNodes[0].className.split('_')[1]; showSpoiler[splrType] = showSpoiler[splrType]?0:1; if(showSpoiler[splrType]) showSpoilers(splrType); else hideSpoilers(splrType); } function initSpoilers { var Divs= document.getElementsByTagName("div"); for (i=0;i<Divs.length;i++) { if (hasClass(Divs[i], "splr")) { Divs[i].onclick = toggleSpoilers; } }  var cookies = document.cookie.split("; "); for (var i=0; i < cookies.length; i++) { // a name/value pair (a crumb) is separated by an equal sign if(cookies[i].indexOf('showspoiler')!=-1) { var crumbs = cookies[i].split("="); var splrType = crumbs[0].split('_')[1]; /* cookie="showspoiler_dao=1", crumbs[0] = "showspoiler_dao", splrType="dao" */ var splrValue = crumbs[1];

showSpoiler[splrType]=splrValue; alert('splrType: '+splrType+ 'splrValue: '+splrValue); if(parseInt(splrValue)) showSpoilers(splrType); else hideSpoilers(splrType); } } }

var spoilers = true; function loadSpoilers { if(spoilers) initSpoilers; } addOnloadHook(loadSpoilers);