Jump to content

MediaWiki:Common.js: Difference between revisions

From Once Human Guide
No edit summary
No edit summary
Line 2: Line 2:
   $(function () {
   $(function () {


    // === SAFE DROPDOWN SYSTEM (matches your working pages) ===
     document.querySelectorAll('.mw-dropdown-ui').forEach(container => {
     document.querySelectorAll('.mw-dropdown-ui').forEach(container => {
       const select = container.querySelector('select');
       const select = container.querySelector('select');
       const sections = container.querySelectorAll('.dropdown-section');
       const output = container.querySelector('.mw-dropdown-output');


       if (!select) return;
       if (!select || !output) return;
 
      const options = {};
 
      // Collect all hidden content blocks
      container.querySelectorAll('[data-value]').forEach(el => {
        options[el.getAttribute('data-value')] = el.innerHTML;
        el.style.display = 'none'; // hide source blocks
      });


       select.addEventListener('change', function () {
       select.addEventListener('change', function () {
         sections.forEach(s => s.style.display = 'none');
         const value = this.value;
        output.innerHTML = options[value] || "Provide information here";
      });


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


   });
   });
});
});

Revision as of 20:59, 21 April 2026

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

    document.querySelectorAll('.mw-dropdown-ui').forEach(container => {
      const select = container.querySelector('select');
      const output = container.querySelector('.mw-dropdown-output');

      if (!select || !output) return;

      const options = {};

      // Collect all hidden content blocks
      container.querySelectorAll('[data-value]').forEach(el => {
        options[el.getAttribute('data-value')] = el.innerHTML;
        el.style.display = 'none'; // hide source blocks
      });

      select.addEventListener('change', function () {
        const value = this.value;
        output.innerHTML = options[value] || "Provide information here";
      });

    });

  });
});