MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 8: | Line 8: | ||
if (!select || !output) return; | if (!select || !output) return; | ||
const | // Build lookup from hidden content | ||
const map = {}; | |||
container.querySelectorAll('[data-value]').forEach(el => { | container.querySelectorAll('[data-value]').forEach(el => { | ||
map[el.getAttribute('data-value')] = el.innerHTML; | |||
el.style.display = 'none'; | el.style.display = 'none'; | ||
}); | }); | ||
select.addEventListener('change', function () { | select.addEventListener('change', function () { | ||
const | const val = this.value; | ||
output.innerHTML = | 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] || "";
});
});
});
});