Toggle menu
Toggle preferences menu
Toggle personal menu
Not logged in
Your IP address will be publicly visible if you make any edits.

MediaWiki:Citizen.js: Difference between revisions

MediaWiki interface page
No edit summary
No edit summary
Line 33: Line 33:
}
}


// === Handle direct URL loads with a hash ===
// === Handle direct URL loads with a hash (page load) ===
mw.hook('wikipage.content').add(function() {
mw.hook('wikipage.content').add(function() {
   if (window.innerWidth >= 768) {
   if (window.innerWidth >= 768) {
Line 39: Line 39:
     if (hash && hash.length > 1) {
     if (hash && hash.length > 1) {
       const headingId = hash.substring(1);
       const headingId = hash.substring(1);
       const heading = document.getElementById(headingId);
       setTimeout(() => { // 🔥 Delay slightly AFTER page render
      if (heading) {
        const heading = document.getElementById(headingId);
        expandParentSectionIfNeeded(heading);
        if (heading) {
          expandParentSectionIfNeeded(heading);


        setTimeout(() => {
          setTimeout(() => {
          heading.scrollIntoView({ behavior: 'smooth', block: 'start' });
            heading.scrollIntoView({ behavior: 'smooth', block: 'start' });
        }, 50);
          }, 50);
       }
        }
       }, 100); // 100ms delay to ensure DOM ready
     }
     }
   }
   }
});
});


// === Hook into Citizen TOC clicks ===
// === Hook into Citizen TOC clicks (live clicking) ===
mw.hook('wikipage.content').add(function() {
mw.hook('wikipage.content').add(function() {
   if (window.innerWidth >= 768) {
   if (window.innerWidth >= 768) {
Line 57: Line 59:
       const citizenToc = require('skins.citizen.toc');
       const citizenToc = require('skins.citizen.toc');


       const originalOnHeadingClick = citizenToc.props.onHeadingClick;
       const originalOnHeadingClick = citizenToc.props.onHeadingClick
 
      citizenToc.props.onHeadingClick = function(id) {
        const headingId = id.replace(/^toc-/, ''); // Remove toc- prefix
        const heading = document.getElementById(headingId);
        if (heading) {
          expandParentSectionIfNeeded(heading);
 
          // Scroll manually without waiting
          setTimeout(() => {
            heading.scrollIntoView({ behavior: 'smooth', block: 'start' });
          }, 50);
        }
 
        if (originalOnHeadingClick) {
          originalOnHeadingClick(id);
        }
      };
    });
  }
});