MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 113: | Line 113: | ||
var translatableSpans = []; | var translatableSpans = []; | ||
function watchTocActive() { | |||
var toc = document.querySelector('.vector-toc'); | |||
if (!toc || toc._grObserved) return; | |||
toc._grObserved = true; | |||
var observer = new MutationObserver(function (mutations) { | |||
mutations.forEach(function (m) { | |||
if (m.attributeName !== 'class') return; | |||
var li = m.target; | |||
var link = li.querySelector(':scope > .vector-toc-link'); | |||
if (!link) return; | |||
if (li.classList.contains('vector-toc-list-item-active')) { | |||
link.style.color = '#f57c00'; | |||
link.style.fontWeight = '700'; | |||
// Auto-expand: find the toggle button and trigger it if collapsed | |||
var toggle = li.querySelector(':scope > .vector-toc-toggle'); | |||
if (toggle && toggle.getAttribute('aria-expanded') === 'false') { | |||
toggle.click(); | |||
} | } | ||
} | |||
// Also expand parent if this is a level-2 item | |||
var parentLi = li.closest('.vector-toc-level-1'); | |||
if (parentLi) { | |||
var parentToggle = parentLi.querySelector(':scope > .vector-toc-toggle'); | |||
if (parentToggle && parentToggle.getAttribute('aria-expanded') === 'false') { | |||
parentToggle.click(); | |||
} | |||
} | |||
} else { | |||
link.style.color = ''; | |||
link.style.fontWeight = ''; | |||
} | |||
}); | }); | ||
}); | |||
toc.querySelectorAll('.vector-toc-list-item').forEach(function (li) { | |||
observer.observe(li, { attributes: true, attributeFilter: ['class'] }); | |||
}); | |||
} | |||
function applyScript(script) { | function applyScript(script) { | ||