MediaWiki:Common.js: Difference between revisions

From TANGOWIKI-TITAF
No edit summary
No edit summary
Line 1: Line 1:
/* Any JavaScript here will be loaded for all users on every page load. */
mw.loader.using('jquery').done(function () {
mw.loader.using('jquery').done(function () {
   $(document).ready(function () {
   $(document).ready(function () {
    // Wait for Select2 to fully initialize
     setTimeout(function () {
     setTimeout(function () {
      // Target Composer and Lyricist token fields
       $('select[name="Recording[Composer][]"], select[name="Recording[Lyricist][]"]').on('select2:select', function () {
       $('select[name="Recording[Composer][]"], select[name="Recording[Lyricist][]"]').on('select2:select', function () {
         const $select = $(this);
         const $select = $(this);


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

Revision as of 20:49, 26 May 2025

mw.loader.using('jquery').done(function () {
  $(document).ready(function () {
    setTimeout(function () {
      // Target Composer and Lyricist token fields
      $('select[name="Recording[Composer][]"], select[name="Recording[Lyricist][]"]').on('select2:select', function () {
        const $select = $(this);

        setTimeout(function () {
          $select.find('option:selected').each(function () {
            const label = $(this).text();
            const match = label.match(/\((TITAF-P-\d+)\)$/); // Look for pattern: (TITAF-P-1234567)
            if (match) {
              const id = match[1];
              $(this).text(id).val(id);
            }
          });
        }, 50);
      });
    }, 500);
  });
});