MediaWiki:Common.js: Difference between revisions
mNo edit summary |
mNo edit summary |
||
| Line 116: | Line 116: | ||
mw.hook('wikipage.content').add(function () { | mw.hook('wikipage.content').add(function () { | ||
const hash = location.hash.replace('#','') | const hash = window.location.hash; | ||
if (!hash) return; // do nothing if no anchor | |||
const id = hash.replace('#',''); | |||
setTimeout(function(){ | setTimeout(function(){ | ||
const item = document.querySelector('.ooo-browser__item[data-target="'+ | const item = document.querySelector('.ooo-browser__item[data-target="'+id+'"]'); | ||
const panel = document.getElementById( | const panel = document.getElementById(id); | ||
if (!item || !panel) return; | if (!item || !panel) return; | ||
| Line 129: | Line 131: | ||
if (!browser) return; | if (!browser) return; | ||
browser.querySelectorAll('.ooo-browser__item') | browser.querySelectorAll('.ooo-browser__item') | ||
.forEach(el => el.classList.remove('is-active')); | .forEach(el => el.classList.remove('is-active')); | ||
browser.querySelectorAll('.ooo-browser__info') | browser.querySelectorAll('.ooo-browser__info') | ||
.forEach(el => el.classList.remove('is-active')); | .forEach(el => el.classList.remove('is-active')); | ||
item.classList.add('is-active'); | |||
panel.classList.add('is-active'); | panel.classList.add('is-active'); | ||
panel.scrollIntoView({block:'start'}); | |||
panel.scrollIntoView({ block:'start | |||
}, 200); | },200); | ||
}); | }); | ||