Difference between revisions of "MediaWiki:Common.js"
Jump to navigation
Jump to search
m (Forgot ;.) |
m (Right, variables cannot be called "switch".) |
||
Line 13: | Line 13: | ||
function collapseReason(id) { | function collapseReason(id) { | ||
var content = document.getElementById("reasonContent-" + id); | var content = document.getElementById("reasonContent-" + id); | ||
var | var rSwitch = document.getElementById("reasonSwitch-" + id); | ||
if(content.style.display=="none") { | if(content.style.display=="none") { | ||
content.style.display = "block"; | content.style.display = "block"; | ||
rSwitch.innerHTML = reasonCaptionHide; | |||
} else { | } else { | ||
content.style.display = "none"; | content.style.display = "none"; | ||
rSwitch.innerHTML = reasonCaptionShow; | |||
} | } | ||
} | } | ||
Line 28: | Line 28: | ||
for(var i = 0; i < divs.length; i++) { | for(var i = 0; i < divs.length; i++) { | ||
if(hasClass(divs[i], "reasonContainer") { | if(hasClass(divs[i], "reasonContainer") { | ||
var | var rSwitch = divs[i].childNodes[0].childNodes[1]; | ||
var content = divs[i].childNodes[1]; | var content = divs[i].childNodes[1]; | ||
Line 39: | Line 39: | ||
link.appendChild(linkCaption); | link.appendChild(linkCaption); | ||
rSwitch.appendChild(link); | |||
reasonIndex++; | reasonIndex++; |
Revision as of 00:35, 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 rSwitch = document.getElementById("reasonSwitch-" + id); if(content.style.display=="none") { content.style.display = "block"; rSwitch.innerHTML = reasonCaptionHide; } else { content.style.display = "none"; rSwitch.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 rSwitch = 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); rSwitch.appendChild(link); reasonIndex++; } } } addOnloadHook(createAllReasonButtons); /*</pre>*/