User:Bdesham/common.js: Difference between revisions
Content deleted Content added
Amorymeltzer (talk | contribs) m Remove legacy globals per phab:T72470 (see VPT notice) (revert and ping me if broken!) (via WP:JWB) |
m Replace getElementsByClassName |
||
Line 15: | Line 15: | ||
var tdpw = Math.floor((width - 150) / tdwidth); |
var tdpw = Math.floor((width - 150) / tdwidth); |
||
var tables = |
var tables = document.querySelectorAll('table.gallery'); |
||
if (tables.length == 0) |
if (tables.length == 0) |
||
Line 22: | Line 22: | ||
for (var tablecount = 0; tablecount < tables.length; tablecount++) { |
for (var tablecount = 0; tablecount < tables.length; tablecount++) { |
||
var t = tables[tablecount]; |
var t = tables[tablecount]; |
||
var divs = |
var divs = t.querySelectorAll('div.gallerybox'); |
||
while (t.firstChild) |
while (t.firstChild) |
||
t.removeChild(t.firstChild); |
t.removeChild(t.firstChild); |
Latest revision as of 17:00, 12 October 2022
// 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;