User:GreyCat/comparison.js
Appearance
Note: After saving, changes may not occur immediately. Click here to learn how to bypass your browser's cache.
- Mozilla / Firefox / Safari: hold down Shift while clicking Reload, or press Ctrl-Shift-R (Cmd-Shift-R on Apple Mac);
- Internet Explorer: hold Ctrl while clicking Refresh, or press Ctrl-F5;
- Konqueror: simply click the Reload button, or press F5;
- Opera users may need to completely clear their cache in Tools→Preferences.
Warning: Malicious code can compromise your account. Page preview will cause your web browser to execute this page's content as code under some skins, including Monobook. If you have any questions about any code you plan to add, you can ask at the appropriate reading room. |
Documentation for this script can be added at User:GreyCat/comparison. |
// Comparison tables extension
// (C) GreyCat, 2006
// License: GPLv2
//
// Note: changes to this file may affect many users;
// please discuss on the talk page before editing.
function switchColumn(el, col) {
var tbl = el.parentNode.parentNode.nextSibling;
var state = el.checked ? '' : 'none';
for (var i = 0; i < tbl.rows.length; i++) {
var row = tbl.rows[i];
row.cells[col].style.display = state;
}
}
function processTable(tbl) {
var headrow = tbl.rows[0];
var selector = '';
for (var i = 0; i < headrow.cells.length; i++) {
var el = headrow.cells[i];
selector += '<div><input type="checkbox" checked="1" onclick="javascript:switchColumn(this, ' + i + ');" /> ' + el.textContent + '</div>';
}
var selectorDiv = document.createElement('DIV');
selectorDiv.innerHTML = selector;
tbl.parentNode.insertBefore(selectorDiv, tbl);
}
function setupComparisonTables() {
var notice = document.getElementById('comparison_notice');
if (notice) {
notice.style.display = 'none';
var tables = document.getElementsByTagName('TABLE');
for (var i = 0; i < tables.length; i++) {
if (tables[i].className == 'wikitable') {
processTable(tables[i]);
}
}
}
}
$(setupComparisonTables);