MediaWiki:Common.js: Difference between revisions

Content deleted Content added
No edit summary
No edit summary
Line 141:
document.body;
 
// Collect headings (H2–H5;H2–H6). h6Prefer isspans boldwith body.mw-headline text,(stable excludedanchor from the TOCids).
// Prefer spans with .mw-headline (stable anchor ids)
var items = [];
var headings = root.querySelectorAll('h2, h3, h4, h5, h6');
headings.forEach(function (h) {
var level = parseInt(h.tagName.slice(1), 10);
if (level < 2 || level > 56) return;
var headline = h.querySelector('.mw-headline') || h;
var id = headline.id || h.id;
Line 691 ⟶ 690:
 
 
/* ── Hide DEEP (nested) level-6 headings from the sidebar (Vector) TOC ─────────────────────────────
The doc pages carry repeated h6 sub-entries that clutter the TOC. MediaWiki's
MediaWiki's TOC classes (vector-toc-level-N) encode only a COMPACTED nesting depth, not
depth, NOT the original heading tag — when levels jump (h3->h6) it still only
incrementsthe oneoriginal level —tag, so CSS cannot reliablycan't target h6. Resolve— resolve each TOCentry to its body
heading instead. We hide ONLY NESTED h6: a TOP-LEVEL section that happens to
entry to its body heading and hide the ones that are actually <h6>. Safe: it
be h6 (e.g. Cover / Audit Information) is KEPT, because hiding a numbered
only ever hides h6 (never h2–h5). The mobile overlay excludes h6 separately
top-level entry leaves a gap in MediaWiki's static TOC numbers (0 -> 3). */
(above). */
(function () {
function headingFor(anchor) {
Line 717 ⟶ 716:
if (href.charAt(0) !== '#' || href.length < 2) { return; }
var h = headingFor(href.slice(1));
if (!h &&|| h.tagName =!== 'H6') { li.style.display = 'none'return; }
// Only hide NESTED h6 (deep repeated sub-entries). A top-level h6 section
// is kept so the top-level numbering stays contiguous.
var nested = li.parentElement && li.parentElement.closest &&
li.parentElement.closest('.vector-toc-list-item');
if (nested) { li.style.display = 'none'; }
});
}