MediaWiki:Mobile.js: Difference between revisions

Content deleted Content added
No edit summary
Tag: Reverted
No edit summary
Tag: Reverted
Line 162:
})();
 
// CapSach — expand all collapsedforce sections expanded on the mobileMobileFrontend site (all mobile skins)
(function () {
// Only run on the MobileFrontend mobile site (works for Minerva/MobileFrontend, Vector, etc.)
ifvar (document.body &&= !document.body.classList.contains('skin-minerva')) return;
if (!body || !body.classList.contains('mw-mf')) return; // detect mobile view reliably
 
function togglesToOpen() {
var set = new Set();
 
// Newer 'MF markup: <section[ aria-expanded="false"] ><h2 .class="section-heading'">…</h2>
document.querySelectorAll('section[aria-expanded="false"] > .section-heading')
headings .forEach(function (h) { hset.clickadd(h); });
 
// Classic MF markup: .collapsible-block (content) with a preceding heading toggle
document.querySelectorAll('.collapsible-block').forEach(function (block) {
if (block.classList.contains('open-block')) return; // already open
var prev = block.previousElementSibling;
if (prev && (prev.classList.contains('collapsible-heading') || prev.classList.contains('section-heading'))) {
set.add(prev);
); }
});
 
// Fallback: any collapsed heading control that advertises its state
document.querySelectorAll('.section-heading[aria-expanded="false"]')
.forEach(function (h) { set.add(h); });
 
return Array.from(set);
}
 
function click(el) {
el.dispatchEvent(new MouseEvent('click', { bubbles: true, cancelable: true, view: window }));
}
 
function expandAll() {
togglesToOpen().forEach(click);
// Heuristics that work across MF releases; safe to no-op if nothing matches
var headings = document.querySelectorAll(
'.collapsible-block:not(.open-block) .section-heading,' +
'section[aria-expanded="false"] > .section-heading'
);
headings.forEach(function (h) { h.click(); });
}
 
function init() {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', expandAll);
} else {
expandAll();
 
// If MF re-renders content (after edits, previews, etc.), expand again
if (window.MutationObserver) {
var obs = new MutationObserver(function () {
var pending = togglesToOpen();
if (pending.length) pending.forEach(click);
});
obs.observe(document.getElementById('content') || document.body, {
subtree: true, childList: true, attributes: true, attributeFilter: ['class', 'aria-expanded']
});
}
}
 
// Wait for MobileFrontend startup, then run; also run on content refreshes
if (window.mw && mw.loader) {
mw.loader.using('mobile.startup').then(function () {
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', expandAllinit);
} else {
init();
}
if (mw.hook) mw.hook('wikipage.content').add(init);
});
} else {
// Very defensive fallback
if (document.readyState === 'loading') document.addEventListener('DOMContentLoaded', init); else init();
}
})();