MediaWiki:Common.js

/* Any JavaScript here will be loaded for all users on every page load. */

var captionShow = 'show'; var captionHide = 'hide';

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 toggleShowCell(which) { el = which.parentNode.parentNode.getElementsByTagName('td')[0].getElementsByTagName('div')[0]; if ( el.style.overflow == 'visible' || !el.style.overflow ) { el.style.overflow = 'hidden'; el.style.height = '50px'; which.innerHTML = captionShow; } else { el.style.overflow = 'visible'; el.style.height = 'auto'; which.innerHTML = captionHide; } }

function findShowHideElements { var tables = document.getElementById("content").getElementsByTagName('table'); for(var i = 0; i<tables.length; i++) { if(hasClass(tables[i], 'infobox')) { var trs = tables[i].getElementsByTagName('tr'); for(var j = 0; j<trs.length; j++) { if(trs[j].getElementsByTagName('td').length==0) continue; if(hasClass(trs[j].getElementsByTagName('td')[0], 'hideablecell')) { var a = document.createElement('a'); a.setAttribute('href', 'javascript://'); a.setAttribute('onclick', 'toggleShowCell(this);'); a.appendChild(document.createTextNode(captionShow)); th = trs[j].getElementsByTagName('th')[0]; th.appendChild(document.createElement('br')); th.appendChild(document.createTextNode('[')); th.appendChild(a); th.appendChild(document.createTextNode(']')); trs[j].getElementsByTagName('td')[0].innerHTML = ' ' + trs[j].getElementsByTagName('td')[0].innerHTML + ' '; toggleShowCell(a); }     }    }  } } addOnloadHook(findShowHideElements);

function alternate_init { var tables = getElementsByClassName(document, "table", "alternateable"); for(var ti = 0; ti < tables.length; ti++) { ts_alternate(tables[ti]); } } addOnloadHook(alternate_init);

function ts_alternate(table) { // Take object table and get all it's tbodies. var tableBodies = table.getElementsByTagName("tbody"); // Loop through these tbodies for (var i = 0; i < tableBodies.length; i++) { // Take the tbody, and get all it's rows var tableRows = tableBodies[i].getElementsByTagName("tr"); // Loop through these rows // Start at 1 because we want to leave the heading row untouched var curRow = 0 var sections = new Array; var s = 0; sections[s] = new Array; for (var j = 0; j < tableRows.length; j++) { if(tableRows[j].parentNode != tableBodies[i]) continue; if(tableRows[j].tagName != 'TR') continue; var ignore = false; var oldClasses = tableRows[j].className.split(" "); var newClassName = ""; for (var k = 0; k < oldClasses.length; k++) { if (oldClasses[k] == "alternate-ignore") ignore = true; if (oldClasses[k] == "alternate-reset") { curRow = 0; ignore = true; }                                   if (oldClasses[k] != "" && oldClasses[k] != "even" && oldClasses[k] != "odd") newClassName += oldClasses[k] + " "; }           if(curRow==0 && j>0) { s++; sections[s] = new Array; }           if(ignore) { continue; }           sections[s].push(tableRows[j]); curRow++; }       for(var s = 0; s < sections.length; s++) { var l = sections[s].length; if (l<=1) continue; for(var r = 0; r < l; r++) { var row = sections[s][r]; var oldClasses = row.className.split(" "); var newClassName = ""; for (var k = 0; k < oldClasses.length; k++) { if (oldClasses[k] != "" && oldClasses[k] != "even" && oldClasses[k] != "odd") newClassName += oldClasses[k] + " "; }               row.className = newClassName + ((l-r) % 2 == 0 ? "odd" : "even"); }       }    } }