User:Fwangel/monobook.js

From Wikibooks, open books for an open world
Jump to navigation Jump to search
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.
// http://en.wikibooks.org/wiki/User:GreyCat/comparison.js
// 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.
//
// fwangel, 2009-05-13: minor changes
 
function switchColumn(el, col) {
	var tbl = el.parentNode.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 = '<div>';
	for (var i = 0; i < headrow.cells.length; i++) {
		var el = headrow.cells[i];
		selector += '<p style="float:left;width:30%;"><input id="ctecbx' + i + '" type="checkbox" checked="1" onclick="javascript:switchColumn(this, ' + i + ');" /> <label for="ctecbx' + i + '">' + el.textContent + '</label></p>\n';
	}
	selector += '<span class="display:block;font-size:1px;height:1px;clear:both;"></span></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);