MediaWiki:Common.js: Difference between revisions
From TANGOWIKI-TITAF
No edit summary |
No edit summary |
||
| Line 1: | Line 1: | ||
$(document).ready(function () { | $(document).ready(function () { | ||
$('select | $('select').on('select2:select', function (e) { | ||
var | var selectedText = e.params.data.text; | ||
var match = | var match = selectedText.match(/\((TITAF-[^)]+)\)$/); // Extract page ID | ||
if (match) { | if (match) { | ||
var | var pageID = match[1]; | ||
var | var $select = $(this); | ||
var existingOptions = $select.find('option'); | |||
var | |||
// 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'); | |||
} | } | ||
}); | }); | ||
}); | }); | ||
Revision as of 21:07, 26 May 2025
$(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');
}
});
});