MediaWiki:Common.js: Difference between revisions

mNo edit summary
mNo edit summary
 
(4 intermediate revisions by the same user not shown)
Line 116: Line 116:
mw.hook('wikipage.content').add(function () {
mw.hook('wikipage.content').add(function () {


  const hash = window.location.hash;
   if (!location.hash) return;
   if (!hash) return;                 // do nothing if no anchor


   const id = hash.replace('#','');
   const id = location.hash.slice(1);


   setTimeout(function(){
   setTimeout(function(){
Line 140: Line 139:
     panel.classList.add('is-active');
     panel.classList.add('is-active');


    panel.scrollIntoView({block:'start'});
  },150);


   },200);
});
 
/* =========================================================
  OOO Browser controller (click switching)
  ========================================================= */
 
document.addEventListener("click", function (e) {
 
  const item = e.target.closest(".ooo-browser__item");
   if (!item) return;
 
  const browser = item.closest(".ooo-browser");
  if (!browser) return;
 
  const target = item.getAttribute("data-target");
  if (!target) return;
 
  e.preventDefault();
 
  browser.querySelectorAll(".ooo-browser__item")
    .forEach(el => el.classList.remove("is-active"));
 
  browser.querySelectorAll(".ooo-browser__info")
    .forEach(el => el.classList.remove("is-active"));
 
  item.classList.add("is-active");
 
const panel = browser.querySelector("#" + CSS.escape(target));
if (panel) panel.classList.add("is-active");
 
/* update browser URL */
history.replaceState(null, null, "#" + target);


});
});