More actions
No edit summary |
No edit summary |
||
Line 2: | Line 2: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
if (window.innerWidth >= 768) { | if (window.innerWidth >= 768) { // Only on desktop | ||
const idsToCollapse = [ | const idsToCollapse = [ | ||
'Muling', 'Misc', 'Anti-ban', 'Anti-PK', 'Trip_Settings', 'Skills_Settings', 'Equipment' | 'Muling', 'Misc', 'Anti-ban', 'Anti-PK', 'Trip_Settings', 'Skills_Settings', 'Equipment' | ||
]; | ]; | ||
idsToCollapse.forEach(function(rawId) { | mw.hook('citizen-collapsibles-init').add(function() { | ||
idsToCollapse.forEach(function(rawId) { | |||
var id = rawId.replace(/ /g, "_"); | |||
var header = document.getElementById(id); | |||
if (!header) return; | |||
var section = header.closest('.citizen-section-heading'); | var section = header.closest('.citizen-section-heading'); | ||
var content = section?.nextElementSibling; | var content = section?.nextElementSibling; | ||
if (content) | if (!section || !content) return; | ||
} | // --- Manually collapse section --- | ||
} | section.classList.add('citizen-section-collapsed'); // Add collapsed class | ||
content.style.display = 'none'; // Hide content manually | |||
// --- Remove old Citizen click event if any --- | |||
var newSection = section.cloneNode(true); | |||
section.parentNode.replaceChild(newSection, section); | |||
// --- Bind our clean click handler --- | |||
newSection.addEventListener('click', function() { | |||
if (content.style.display === 'none') { | |||
content.style.display = 'block'; | |||
newSection.classList.remove('citizen-section-collapsed'); | |||
} else { | |||
content.style.display = 'none'; | |||
newSection.classList.add('citizen-section-collapsed'); | |||
} | |||
}); | |||
}); | |||
}); | }); | ||
} | } | ||
}); | }); |
Revision as of 14:25, 25 April 2025
/* All JavaScript here will be loaded for users of the Citizen skin */ $(document).ready(function() { if (window.innerWidth >= 768) { // Only on desktop const idsToCollapse = [ 'Muling', 'Misc', 'Anti-ban', 'Anti-PK', 'Trip_Settings', 'Skills_Settings', 'Equipment' ]; mw.hook('citizen-collapsibles-init').add(function() { idsToCollapse.forEach(function(rawId) { var id = rawId.replace(/ /g, "_"); var header = document.getElementById(id); if (!header) return; var section = header.closest('.citizen-section-heading'); var content = section?.nextElementSibling; if (!section || !content) return; // --- Manually collapse section --- section.classList.add('citizen-section-collapsed'); // Add collapsed class content.style.display = 'none'; // Hide content manually // --- Remove old Citizen click event if any --- var newSection = section.cloneNode(true); section.parentNode.replaceChild(newSection, section); // --- Bind our clean click handler --- newSection.addEventListener('click', function() { if (content.style.display === 'none') { content.style.display = 'block'; newSection.classList.remove('citizen-section-collapsed'); } else { content.style.display = 'none'; newSection.classList.add('citizen-section-collapsed'); } }); }); }); } });