MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
$(function () { | $(function () { | ||
document.querySelectorAll('.mw-dropdown-ui').forEach(container => { | document.querySelectorAll('.mw-dropdown-ui').forEach(container => { | ||
const select = container.querySelector('select'); | const select = container.querySelector('select'); | ||
const | const output = container.querySelector('.mw-dropdown-output'); | ||
if (!select) return; | if (!select || !output) return; | ||
const options = {}; | |||
// Collect all hidden content blocks | |||
container.querySelectorAll('[data-value]').forEach(el => { | |||
options[el.getAttribute('data-value')] = el.innerHTML; | |||
el.style.display = 'none'; // hide source blocks | |||
}); | |||
select.addEventListener('change', function () { | select.addEventListener('change', function () { | ||
const value = this.value; | |||
output.innerHTML = options[value] || "Provide information here"; | |||
}); | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
Revision as of 20:59, 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;
const options = {};
// Collect all hidden content blocks
container.querySelectorAll('[data-value]').forEach(el => {
options[el.getAttribute('data-value')] = el.innerHTML;
el.style.display = 'none'; // hide source blocks
});
select.addEventListener('change', function () {
const value = this.value;
output.innerHTML = options[value] || "Provide information here";
});
});
});
});