User:Tyrok1/monobook.js: Difference between revisions

Commented the code
(Created page with 'function CompareActivate() { var tocEl = document.getElementById("toc"); if(tocEl) { var toctitleEl = document.getElementById("toctitle"); var instructionsEl = toctitleEl.…')
 
(Commented the code)
Line 1:
function CompareActivate()
{
//check to see if we're looking at a task page
var tocEl = document.getElementById("toc");
if(tocEl)
{
//add some instructions
var toctitleEl = document.getElementById("toctitle");
var instructionsEl = toctitleEl.appendChild(document.createElement("p"));
Line 9 ⟶ 11:
instructionsEl.appendChild(document.createElement("br"));
instructionsEl.appendChild(document.createTextNode("Uncheck all boxes to show all languages."));
{
//find all of the links to language sections
var liEls = tocEl.getElementsByTagName("li");
for(var l = 0; l < liEls.length; ++l)
{
//add a checkbox with the language section's <a> name attribute as its value for easier lookup in the refresh function
var checkboxEl = document.createElement("input");
checkboxEl.setAttribute("type", "checkbox");
Line 21 ⟶ 26:
liEls[l].insertBefore(checkboxEl, liEls[l].firstChild);
}
//and refresh the display for good measure (sometimes browsers like to save <input> states between reloads)
CompareRefresh();
}
Line 27 ⟶ 34:
function CompareRefresh()
{
//refresh the display of the language sections displayed under the TOC
//first, check to see if we're looking at a task page
var tocEl = document.getElementById("toc");
var languages = new Array();
Line 32 ⟶ 41:
if(tocEl)
{
//find all of the checkboxes within the TOC
var inputEls = tocEl.getElementsByTagName("input");
for(var i = 0; i < inputEls.length; ++i)
{
//if it's one of the ones we added earlier, log the checked status to the languages array for later use
if(inputEls[i].getAttribute("name").substring(0, ("CompareLanguage").length) == "CompareLanguage")
{
Line 41 ⟶ 52:
}
}
//now, find all <a> tags with name attributes
}
var aEls = document.getElementsByTagName("a");
for(var a = 0; a < aEls.length; ++a)
{
if(aEls[a].name && typeof languages[aEls[a].name] != "undefined")
{
if(aEls[a].name && typeof languages[aEls[a].name] != "undefined")
var topicEls = new Array();
var curEl = aEls[a].nextSibling;
while(curEl && (!curEl.tagName || curEl.tagName.toLowerCase() != "a" || !curEl.name || typeof languages[curEl.name] == "undefined"))
{
//we can assume that this is a language section
topicEls[topicEls.length] = curEl;
//make a list of all of the elements between this <a> tag and the next one that has a name attribute
curEl = curEl.nextSibling;
var topicEls = new Array();
};
for( var ecurEl = 0; e < topicElsaEls[a].lengthnextSibling; ++e)
while(curEl && (!curEl.tagName || curEl.tagName.toLowerCase() != "a" || !curEl.name || typeof languages[curEl.name] == "undefined"))
{
{
if(topicEls[e].tagName && topicEls[e].style)
topicEls[topicEls.length] = curEl;
var curEl = aEls[a]curEl.nextSibling;
};
//either show or hide them depending on the language's checked status (of if none are checked, display all)
for(var e = 0; e < topicEls.length; ++e)
{
if(topicEls[e].style.displaytagName =&& (numChecked < 1 || languagestopicEls[aEls[ae].name] ? "" : "none"style);
{
topicEls[e].style.display = (numChecked < 1 || languages[aEls[a].name] ? "" : "none");
}
}
}
Line 65 ⟶ 81:
}
 
//register the comparison script with the window's load event
if(window.addEventListener)
{
Anonymous user