MediaWiki:Common.js

From TANGOWIKI-TITAF
Revision as of 21:07, 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.
$(document).ready(function () {
  $('select').on('select2:select', function (e) {
    var selectedText = e.params.data.text;
    var match = selectedText.match(/\((TITAF-[^)]+)\)$/); // Extract page ID
    if (match) {
      var pageID = match[1];
      var $select = $(this);
      var existingOptions = $select.find('option');

      // Remove the long label
      existingOptions.each(function () {
        if ($(this).text() === selectedText) {
          $(this).remove();
        }
      });

      // Add the cleaned ID
      var newOption = new Option(pageID, pageID, true, true);
      $select.append(newOption).trigger('change');
    }
  });
});