MediaWiki:Mobile.js: Difference between revisions
Content deleted Content added
No edit summary Tag: Reverted |
No edit summary Tag: Reverted |
||
Line 162:
})();
// CapSach —
(function () {
// Only run on the MobileFrontend mobile site (works for Minerva
if (!body || !body.classList.contains('mw-mf')) return; // detect mobile view reliably
function togglesToOpen() {
var set = new Set();
document.querySelectorAll('section[aria-expanded="false"] > .section-heading')
// 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);
▲ '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') {
} 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();
}
})();
| |||