MediaWiki:Common.js: Difference between revisions
From EQOA Sandstorm Wiki
Jump to navigationJump to search
RenodorDev (talk | contribs) No edit summary |
RenodorDev (talk | contribs) No edit summary |
||
| Line 1: | Line 1: | ||
/* Any JavaScript here will be loaded for all users on every page load. */ | /* Any JavaScript here will be loaded for all users on every page load. */ | ||
( function () { | |||
// only run when DOM ready | |||
function initRaidChecks() { | |||
// find containers | |||
var containers = document.querySelectorAll('.raid-checkboxify'); | |||
if (!containers.length) return; | |||
containers.forEach(function (container, idx) { | |||
var links = Array.from(container.querySelectorAll('a')); | |||
links.forEach(function (a, i) { | |||
// skip if it's already processed | |||
if (a.classList.contains('raid-processed')) return; | |||
// create checkbox input | |||
var cb = document.createElement('input'); | |||
cb.type = 'checkbox'; | |||
cb.className = 'raid-checkbox-input'; | |||
cb.style.marginRight = '8px'; | |||
cb.style.verticalAlign = 'middle'; | |||
// wrap the link & checkbox in a label so clicking text toggles checkbox | |||
var label = document.createElement('label'); | |||
label.style.display = 'block'; | |||
label.style.cursor = 'pointer'; | |||
// move link inside label | |||
a.parentNode.insertBefore(label, a); | |||
label.appendChild(cb); | |||
label.appendChild(a); | |||
a.classList.add('raid-processed'); | |||
// restore state from localStorage | |||
var key = 'raidcheck:' + (document.title || location.pathname) + ':' + a.getAttribute('href'); | |||
try { | |||
var stored = localStorage.getItem(key); | |||
if (stored === '1') cb.checked = true; | |||
} catch (e) {} | |||
cb.addEventListener('change', function () { | |||
try { | |||
if (cb.checked) localStorage.setItem(key, '1'); | |||
else localStorage.removeItem(key); | |||
} catch (e) {} | |||
}); | |||
}); | |||
}); | |||
} | |||
if (document.readyState === 'loading') { | |||
document.addEventListener('DOMContentLoaded', initRaidChecks); | |||
} else { | |||
initRaidChecks(); | |||
} | |||
})(); | |||
Revision as of 11:57, 27 November 2025
/* Any JavaScript here will be loaded for all users on every page load. */
( function () {
// only run when DOM ready
function initRaidChecks() {
// find containers
var containers = document.querySelectorAll('.raid-checkboxify');
if (!containers.length) return;
containers.forEach(function (container, idx) {
var links = Array.from(container.querySelectorAll('a'));
links.forEach(function (a, i) {
// skip if it's already processed
if (a.classList.contains('raid-processed')) return;
// create checkbox input
var cb = document.createElement('input');
cb.type = 'checkbox';
cb.className = 'raid-checkbox-input';
cb.style.marginRight = '8px';
cb.style.verticalAlign = 'middle';
// wrap the link & checkbox in a label so clicking text toggles checkbox
var label = document.createElement('label');
label.style.display = 'block';
label.style.cursor = 'pointer';
// move link inside label
a.parentNode.insertBefore(label, a);
label.appendChild(cb);
label.appendChild(a);
a.classList.add('raid-processed');
// restore state from localStorage
var key = 'raidcheck:' + (document.title || location.pathname) + ':' + a.getAttribute('href');
try {
var stored = localStorage.getItem(key);
if (stored === '1') cb.checked = true;
} catch (e) {}
cb.addEventListener('change', function () {
try {
if (cb.checked) localStorage.setItem(key, '1');
else localStorage.removeItem(key);
} catch (e) {}
});
});
});
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', initRaidChecks);
} else {
initRaidChecks();
}
})();