MediaWiki:Common.js: Difference between revisions
No edit summary |
No edit summary |
||
| Line 113: | Line 113: | ||
var translatableSpans = []; | var translatableSpans = []; | ||
function | // ── TOC active highlight (CSS-driven, MutationObserver backup) ── | ||
var | function watchTocActive() { | ||
if (! | var toc = document.querySelector('.vector-toc'); | ||
if (!toc || toc._grObserved) return; | |||
toc._grObserved = true; | |||
var | 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'; | |||
} else { | |||
link.style.color = ''; | |||
link.style.fontWeight = ''; | |||
} | |||
}); | |||
}); | |||
toc.querySelectorAll('.vector-toc-list-item').forEach(function (li) { | |||
observer.observe(li, { attributes: true, attributeFilter: ['class'] }); | |||
}); | }); | ||
} | } | ||