MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 39: | Line 39: | ||
button.onclick = function () { | button.onclick = function () { | ||
// Close any open dropdown | |||
document.querySelectorAll('.dropdown-list').forEach(el => el.remove()); | document.querySelectorAll('.dropdown-list').forEach(el => el.remove()); | ||
| Line 68: | Line 69: | ||
container.appendChild(wrapper); | container.appendChild(wrapper); | ||
} | } | ||
/* ================= RESULT SYSTEM (SAFE VERSION) ================= */ | |||
function updateResult() { | function updateResult() { | ||
const result = document. | const result = document.getElementById("result-box"); | ||
if (!result) return; | if (!result) return; | ||
| Line 78: | Line 81: | ||
} | } | ||
const key = selectedLeft + "__" + selectedRight; | |||
const data = document.querySelector('[data-key="' + key + '"]'); | |||
if (!data) { | |||
result.style.display = "block"; | |||
result.innerHTML = "No data found."; | |||
return; | |||
} | |||
result.innerHTML = data | result.style.display = "block"; | ||
result.innerHTML = data.innerHTML; | |||
} | } | ||
/* ================= INIT DROPDOWNS ================= */ | |||
document.querySelectorAll('[data-dropdown-group]').forEach(group => { | document.querySelectorAll('[data-dropdown-group]').forEach(group => { | ||
| Line 90: | Line 101: | ||
const right = group.querySelector('[data-right]'); | const right = group.querySelector('[data-right]'); | ||
if (left) createDropdown(left, left.dataset.label, JSON.parse(left.dataset.options), "left"); | if (left) { | ||
if (right) createDropdown(right, right.dataset.label, JSON.parse(right.dataset.options), "right"); | createDropdown( | ||
left, | |||
left.dataset.label, | |||
JSON.parse(left.dataset.options), | |||
"left" | |||
); | |||
} | |||
if (right) { | |||
createDropdown( | |||
right, | |||
right.dataset.label, | |||
JSON.parse(right.dataset.options), | |||
"right" | |||
); | |||
} | |||
}); | }); | ||
}); | }); | ||
}); | }); | ||
Revision as of 19:35, 21 April 2026
mw.loader.using('mediawiki.util').then(function () {
$(function () {
/* ================= TAB SYSTEM ================= */
document.querySelectorAll('.mw-tab-buttons').forEach(group => {
const buttons = group.querySelectorAll('.mw-tab-btn');
buttons.forEach(btn => {
btn.onclick = function () {
const tabId = this.dataset.tab;
const container = group.closest('.mw-tab-content') || document;
container.querySelectorAll('.mw-tab-content').forEach(c => c.style.display = 'none');
container.querySelectorAll('.mw-tab-btn').forEach(b => b.classList.remove('active'));
this.classList.add('active');
const target = container.querySelector('#' + tabId);
if (target) target.style.display = 'block';
};
});
if (buttons.length) buttons[0].click();
});
/* ================= DROPDOWN SYSTEM ================= */
let selectedLeft = null;
let selectedRight = null;
function createDropdown(container, label, options, side) {
const wrapper = document.createElement('div');
const button = document.createElement('button');
button.textContent = label;
let list = null;
button.onclick = function () {
// Close any open dropdown
document.querySelectorAll('.dropdown-list').forEach(el => el.remove());
list = document.createElement('div');
list.className = 'dropdown-list';
Object.keys(options).forEach(key => {
const item = document.createElement('div');
item.textContent = options[key];
item.onclick = function () {
button.textContent = options[key];
if (side === 'left') selectedLeft = key;
if (side === 'right') selectedRight = key;
list.remove();
updateResult();
};
list.appendChild(item);
});
wrapper.appendChild(list);
};
wrapper.appendChild(button);
container.innerHTML = '';
container.appendChild(wrapper);
}
/* ================= RESULT SYSTEM (SAFE VERSION) ================= */
function updateResult() {
const result = document.getElementById("result-box");
if (!result) return;
if (!selectedLeft || !selectedRight) {
result.style.display = "none";
return;
}
const key = selectedLeft + "__" + selectedRight;
const data = document.querySelector('[data-key="' + key + '"]');
if (!data) {
result.style.display = "block";
result.innerHTML = "No data found.";
return;
}
result.style.display = "block";
result.innerHTML = data.innerHTML;
}
/* ================= INIT DROPDOWNS ================= */
document.querySelectorAll('[data-dropdown-group]').forEach(group => {
const left = group.querySelector('[data-left]');
const right = group.querySelector('[data-right]');
if (left) {
createDropdown(
left,
left.dataset.label,
JSON.parse(left.dataset.options),
"left"
);
}
if (right) {
createDropdown(
right,
right.dataset.label,
JSON.parse(right.dataset.options),
"right"
);
}
});
});
});