|
// CapSach — MobileSticky TOC overlay (allUNRESTRICTED: skins;Works phoneon widthsiPad/Desktop/Mobile)
(function () {
// Don’t run on very wide screens (tablet/desktop have native TOC)
if// (window1.matchMedia('( REMOVED the "min-width: 768px)')" check.matches) return;Now runs everywhere.
// Only run on normalpages contentwhere pagesit makes sense (Articles/MainPage)
if (window.mw && mw.config && mw.config.get) {
var isArticleisAllowed = !!mw.config.get('wgIsArticle') || mw.config.get('wgIsMainPage');
if (!isArticleisAllowed) return;
}
});
// Show only if there are enough headings to be useful (match core default)
// CHANGED: Lowered requirement to 1 heading so it always shows if there is any structure
if (items.length < 3) return;
if (items.length < 1) return;
// Create trigger button (bottom-left; avoids “Back to top” on bottom-right)
}
// Force button display immediately
btn.style.display = 'flex'; // reveal trigger now that we know we have headings
btn.style.display = 'flex';
btn.addEventListener('click', openOverlay);
});
// 2. REMOVED the "resize" event listener that was hiding the button.
// Re-hide on rotation/resize to tablet/desktop
// The button now persists on all screen sizes.
window.addEventListener('resize', function () {
if (window.matchMedia('(min-width: 768px)').matches) {
btn.style.display = 'none';
closeOverlay();
} else {
btn.style.display = 'flex';
}
}, { passive: true });
})();
/* Auto‑expand all H2 sections on mobile (Minerva + Vector 2022) */
(function (mw, $) {
// Only do this on narrow viewports (mobile-ish).
if (!matchMedia('(max-width: 760px)').matches) return;
$(document).ready(function() {
// Expand any collapsed section controls inside article content
// Check if the button already exists to prevent duplicates
function expandAllSections(root) {
if ($('#custom-email-btn').length === 0) {
var scope = root || document;
// Create the email button element
var emailBtn = $('<a>', {
id: 'custom-email-btn',
href: 'mailto:services@axabrain.com',
// Simple accessible title
title: 'Contact AXA BRAIN Services'
});
// Add it to the body of the page
// Strategy 1: click real toggles that MobileFrontend/Vector attach
$('body').append(emailBtn);
scope.querySelectorAll(
// Collapsed toggles inside the article content
'.mw-parser-output [aria-expanded="false"], ' +
// …or the <section> wrapper itself (Parsoid/section wrapping)
'section[data-mw-section-id][aria-expanded="false"]'
).forEach(function (toggle) {
// Avoid menus or other UI; stick to the article area
if (!toggle.closest('.mw-parser-output')) return;
// Only click if it looks like a heading/section control
var isHeadingToggle =
toggle.closest('section[data-mw-section-id]') ||
toggle.closest('.mw-heading') ||
toggle.tagName.match(/^H[2-6]$/);
if (isHeadingToggle) {
// Prefer letting the skin/extension handle state via its own click
toggle.dispatchEvent(new MouseEvent('click', { bubbles: true }));
// Belt‑and‑suspenders: normalise state in case the click didn’t attach yet
toggle.setAttribute('aria-expanded', 'true');
toggle.classList.remove('is-collapsed', 'collapsible-heading-collapsed');
var sec = toggle.closest('section[data-mw-section-id]');
if (sec) {
sec.setAttribute('aria-expanded', 'true');
sec.classList.remove('is-collapsed');
}
}
});
// Strategy 2: if a section wrapper exists, ensure its first content block is visible
scope.querySelectorAll('section[data-mw-section-id]').forEach(function (sec) {
var contentAfterHeading =
// New heading wrapper (1.43+)
sec.querySelector('.mw-heading + *') ||
// Legacy structure
sec.querySelector('h2 + *');
if (contentAfterHeading) {
contentAfterHeading.style.removeProperty('display');
contentAfterHeading.style.removeProperty('height');
contentAfterHeading.style.removeProperty('overflow');
sec.setAttribute('aria-expanded', 'true');
}
});
}
// Run when page content is ready, plus a couple of retries because MF decorates async
mw.hook('wikipage.content').add(function ($content) {
var node = ($content && $content[0]) || document;
[0, 300, 900].forEach(function (delay) {
setTimeout(function () { expandAllSections(node); }, delay);
});
});
// If anything inserts new headings later (e.g., gadgets), expand those too
new MutationObserver(function (mutations) {
for (var m of mutations) {
if ([...m.addedNodes].some(function (n) {
return n.querySelector &&
(n.querySelector('[aria-expanded="false"]') ||
n.querySelector('section[data-mw-section-id]'));
})) {
expandAllSections();
break;
}
}
});
}).observe(document.documentElement, { childList: true, subtree: true });
})(mw, jQuery);
|