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;
  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="'+hash+'"]');
     const item = document.querySelector('.ooo-browser__item[data-target="'+id+'"]');
     const panel = document.getElementById(hash);
     const panel = document.getElementById(id);


     if (!item || !panel) return;
     if (!item || !panel) return;
Line 129: Line 131:
     if (!browser) return;
     if (!browser) return;


    // activate correct item
     browser.querySelectorAll('.ooo-browser__item')
     browser.querySelectorAll('.ooo-browser__item')
       .forEach(el => el.classList.remove('is-active'));
       .forEach(el => el.classList.remove('is-active'));


    item.classList.add('is-active');
    // activate correct panel
     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');


    // scroll to panel
     panel.scrollIntoView({block:'start'});
     panel.scrollIntoView({ block:'start', behavior:'instant' });


   }, 200);
   },200);


});
});