Jump to content

MediaWiki:Common.js: Difference between revisions

From Once Human Guide
No edit summary
No edit summary
Line 9: Line 9:
           const tabId = this.dataset.tab;
           const tabId = this.dataset.tab;


           // 🔥 ONLY affect tabs in this group
           // 🔥 Find the nearest container that holds this group
           const container = group.parentElement;
           const container = group.closest('.mw-tab-content') || document;


           container.querySelectorAll(':scope > .mw-tab-content').forEach(c => {
          // Hide ONLY tabs inside this container
           container.querySelectorAll('.mw-tab-content').forEach(c => {
             c.style.display = 'none';
             c.style.display = 'none';
           });
           });
Line 27: Line 28:
       });
       });


       // auto-open first tab in each group
       // auto open first tab
       if (buttons.length > 0) {
       if (buttons.length > 0) {
         buttons[0].click();
         buttons[0].click();

Revision as of 18:14, 21 April 2026

mw.loader.using('mediawiki.util').then(function () {
  $(function () {

    document.querySelectorAll('.mw-tab-buttons').forEach(group => {
      const buttons = group.querySelectorAll('.mw-tab-btn');

      buttons.forEach(btn => {
        btn.addEventListener('click', function () {
          const tabId = this.dataset.tab;

          // 🔥 Find the nearest container that holds this group
          const container = group.closest('.mw-tab-content') || document;

          // Hide ONLY tabs inside this container
          container.querySelectorAll('.mw-tab-content').forEach(c => {
            c.style.display = 'none';
          });

          container.querySelectorAll('.mw-tab-btn').forEach(b => {
            b.classList.remove('active');
          });

          this.classList.add('active');

          const target = container.querySelector('#' + tabId);
          if (target) target.style.display = 'block';
        });
      });

      // auto open first tab
      if (buttons.length > 0) {
        buttons[0].click();
      }
    });

  });
});