Jump to content

MediaWiki:Common.js: Difference between revisions

From Once Human Guide
No edit summary
No edit summary
Line 8: Line 8:
       if (!select || !output) return;
       if (!select || !output) return;


       const options = {};
      // Build lookup from hidden content
       const map = {};


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


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



Revision as of 21:00, 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;

      // Build lookup from hidden content
      const map = {};

      container.querySelectorAll('[data-value]').forEach(el => {
        map[el.getAttribute('data-value')] = el.innerHTML;
        el.style.display = 'none';
      });

      select.addEventListener('change', function () {
        const val = this.value;
        output.innerHTML = map[val] || "";
      });

    });

  });
});