Jump to content

User:Bdesham/common.js

From Wikipedia, the free encyclopedia
Note: After saving, you have to bypass your browser's cache to see the changes. Google Chrome, Firefox, Microsoft Edge and Safari: Hold down the ⇧ Shift key and click the Reload toolbar button. For details and instructions about other browsers, see Wikipedia:Bypass your cache.
// mark all edits as minor by default

if (mw.config.get('wgAction') == 'edit') {
	addOnloadHook(function () {
		document.getElementById('wpMinoredit').checked = true;
	});
}

// make photo galleries take the entire page width

function resize_galleries () {
	var bc = document.getElementById("bodyContent");
	var width = bc.offsetWidth;
	var tdwidth = 155;
	var tdpw = Math.floor((width - 150) / tdwidth);

	var tables = document.querySelectorAll('table.gallery');

	if (tables.length == 0)
		return;

	for (var tablecount = 0; tablecount < tables.length; tablecount++) {
		var t = tables[tablecount];
		var divs = t.querySelectorAll('div.gallerybox');
		while (t.firstChild)
			t.removeChild(t.firstChild);
		var tr = null;
		var done = 0;
		for (var i = 0; i < divs.length; i++) {
			if (done == 0) {
				tr = document.createElement("tr");
				t.appendChild(tr);
			}
			var td = document.createElement("td");
			td.appendChild(divs[i]);
			tr.appendChild(td);
			done++;
			if (done > tdpw)
				done = 0;
		}
	}
}

addOnloadHook(resize_galleries);
window.onresize = resize_galleries;