MediaWiki:Common.js: Difference between revisions
Appearance
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
$(function () { | $(function () { | ||
/* ================= TAB SYSTEM | /* ================= TAB SYSTEM ================= */ | ||
document.querySelectorAll('.mw-tabs').forEach(tabSystem => { | document.querySelectorAll('.mw-tabs').forEach(tabSystem => { | ||
| Line 25: | Line 25: | ||
}); | }); | ||
if (buttons.length) { | |||
if (buttons.length | |||
activateTab(buttons[0].dataset.tab, buttons[0]); | activateTab(buttons[0].dataset.tab, buttons[0]); | ||
} | } | ||
| Line 32: | Line 31: | ||
}); | }); | ||
/* ================= MOD SYSTEM ( | /* ================= OLD DROPDOWN SYSTEM (RESTORED) ================= */ | ||
document.querySelectorAll('.mw-dropdown-ui').forEach(container => { | |||
const label = container.dataset.label || "Select"; | |||
const options = JSON.parse(container.dataset.options || "{}"); | |||
const select = document.createElement('select'); | |||
const defaultOption = document.createElement('option'); | |||
defaultOption.textContent = label; | |||
defaultOption.value = ""; | |||
select.appendChild(defaultOption); | |||
Object.keys(options).forEach(key => { | |||
const opt = document.createElement('option'); | |||
opt.value = key; | |||
opt.textContent = options[key].label; | |||
select.appendChild(opt); | |||
}); | |||
const output = document.createElement('div'); | |||
output.className = 'mw-dropdown-output'; | |||
select.onchange = function () { | |||
const selected = options[this.value]; | |||
output.innerHTML = selected ? selected.content : ""; | |||
}; | |||
container.innerHTML = ''; | |||
container.appendChild(select); | |||
container.appendChild(output); | |||
}); | |||
/* ================= MOD SYSTEM (NEW) ================= */ | |||
document.querySelectorAll('.mod-system').forEach(system => { | document.querySelectorAll('.mod-system').forEach(system => { | ||
Revision as of 19:53, 21 April 2026
mw.loader.using('mediawiki.util').then(function () {
$(function () {
/* ================= TAB SYSTEM ================= */
document.querySelectorAll('.mw-tabs').forEach(tabSystem => {
const buttons = tabSystem.querySelectorAll('.mw-tab-btn');
const contents = tabSystem.querySelectorAll('.mw-tab-content');
function activateTab(tabId, btn) {
contents.forEach(c => c.style.display = 'none');
buttons.forEach(b => b.classList.remove('active'));
const target = tabSystem.querySelector('#' + tabId);
if (target) target.style.display = 'block';
if (btn) btn.classList.add('active');
}
buttons.forEach(btn => {
btn.onclick = function () {
activateTab(this.dataset.tab, this);
};
});
if (buttons.length) {
activateTab(buttons[0].dataset.tab, buttons[0]);
}
});
/* ================= OLD DROPDOWN SYSTEM (RESTORED) ================= */
document.querySelectorAll('.mw-dropdown-ui').forEach(container => {
const label = container.dataset.label || "Select";
const options = JSON.parse(container.dataset.options || "{}");
const select = document.createElement('select');
const defaultOption = document.createElement('option');
defaultOption.textContent = label;
defaultOption.value = "";
select.appendChild(defaultOption);
Object.keys(options).forEach(key => {
const opt = document.createElement('option');
opt.value = key;
opt.textContent = options[key].label;
select.appendChild(opt);
});
const output = document.createElement('div');
output.className = 'mw-dropdown-output';
select.onchange = function () {
const selected = options[this.value];
output.innerHTML = selected ? selected.content : "";
};
container.innerHTML = '';
container.appendChild(select);
container.appendChild(output);
});
/* ================= MOD SYSTEM (NEW) ================= */
document.querySelectorAll('.mod-system').forEach(system => {
const modType = system.dataset.mod;
const dataBlock = document.querySelector('#mod-database [data-mod="' + modType + '"]');
if (!dataBlock) return;
const leftData = JSON.parse(dataBlock.querySelector('[data-left]').dataset.left);
const rightData = JSON.parse(dataBlock.querySelector('[data-right]').dataset.right);
let selectedLeft = null;
let selectedRight = null;
const leftDiv = document.createElement('div');
const rightDiv = document.createElement('div');
const result = document.createElement('div');
result.style.display = "none";
result.style.border = "1px solid #444";
result.style.padding = "10px";
result.style.marginTop = "10px";
function createDropdown(container, options, side) {
const btn = document.createElement('button');
btn.textContent = "Select";
btn.onclick = function () {
document.querySelectorAll('.dropdown-list').forEach(el => el.remove());
const 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 () {
btn.textContent = options[key];
if (side === "left") selectedLeft = key;
if (side === "right") selectedRight = key;
list.remove();
update();
};
list.appendChild(item);
});
container.appendChild(list);
};
container.appendChild(btn);
}
function update() {
if (!selectedLeft || !selectedRight) {
result.style.display = "none";
return;
}
const key = selectedLeft + "__" + selectedRight;
const match = dataBlock.querySelector('[data-key="' + key + '"]');
result.style.display = "block";
result.innerHTML = match ? match.innerHTML : "No data";
}
createDropdown(leftDiv, leftData, "left");
createDropdown(rightDiv, rightData, "right");
system.appendChild(leftDiv);
system.appendChild(rightDiv);
system.appendChild(result);
});
});
});