MediaWiki:Common.js

From TANGOWIKI-TITAF
Revision as of 20:44, 26 May 2025 by Donxello (talk | contribs)

Note: After publishing, you may have to bypass your browser's cache to see the changes.

  • Firefox / Safari: Hold Shift while clicking Reload, or press either Ctrl-F5 or Ctrl-R (⌘-R on a Mac)
  • Google Chrome: Press Ctrl-Shift-R (⌘-Shift-R on a Mac)
  • Edge: Hold Ctrl while clicking Refresh, or press Ctrl-F5.
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using('jquery').done(function () {
  $(document).ready(function () {
    // Wait for Select2 to fully initialize
    setTimeout(function () {
      $('select[name="Recording[Composer][]"], select[name="Recording[Lyricist][]"]').on('select2:select', function () {
        const $select = $(this);

        // Wait a bit to ensure the new option is added
        setTimeout(function () {
          $select.find('option:selected').each(function () {
            const label = $(this).text();
            const match = label.match(/\((TITAF-P-\d+)\)$/); // e.g., "Name (TITAF-P-1234567)"
            if (match) {
              const id = match[1];
              $(this).text(id).val(id);
            }
          });
        }, 50);
      });
    }, 500);
  });
});