More actions
No edit summary |
No edit summary |
||
| Line 2: | Line 2: | ||
$(document).ready(function() { | $(document).ready(function() { | ||
// | // Wait for collapsible elements to be initialized by MediaWiki | ||
mw.hook('wikipage.content').add(function() { | |||
var $ | var $sections = $('.accordion-section'); | ||
// Initialize: disable links in collapsed sections | |||
$sections.each(function() { | |||
if ($(this).hasClass('mw-collapsed')) { | |||
$(this).find('.mw-headline a').css('pointer-events', 'none'); | |||
} | |||
}); | |||
// Handle clicks on headers | |||
$sections.on('click', '.mw-headline', function(e) { | |||
var $section = $(this).closest('.accordion-section'); | |||
var isCollapsed = $section.hasClass('mw-collapsed'); | |||
} | |||
if (isCollapsed) { | |||
// Collapse all other sections | |||
$sections.not($section).addClass('mw-collapsed'); | |||
// Expand this section | |||
$section.removeClass('mw-collapsed'); | |||
// Enable links in this section | |||
$section.find('.mw-headline a').css('pointer-events', 'auto'); | |||
// Disable links in all other sections | |||
$sections.not($section).find('.mw-headline a').css('pointer-events', 'none'); | |||
} else { | |||
// Collapse this section | |||
$section.addClass('mw-collapsed'); | |||
// Disable links in this section | |||
$section.find('.mw-headline a').css('pointer-events', 'none'); | |||
} | |||
// Prevent link click from propagating if collapsed | |||
if (e.target.tagName === 'A' && $section.hasClass('mw-collapsed')) { | |||
e.preventDefault(); | |||
} | |||
}); | |||
}); | }); | ||
}); | }); | ||
Revision as of 07:47, 29 March 2025
/* Any JavaScript here will be loaded for all users on every page load. */
$(document).ready(function() {
// Wait for collapsible elements to be initialized by MediaWiki
mw.hook('wikipage.content').add(function() {
var $sections = $('.accordion-section');
// Initialize: disable links in collapsed sections
$sections.each(function() {
if ($(this).hasClass('mw-collapsed')) {
$(this).find('.mw-headline a').css('pointer-events', 'none');
}
});
// Handle clicks on headers
$sections.on('click', '.mw-headline', function(e) {
var $section = $(this).closest('.accordion-section');
var isCollapsed = $section.hasClass('mw-collapsed');
if (isCollapsed) {
// Collapse all other sections
$sections.not($section).addClass('mw-collapsed');
// Expand this section
$section.removeClass('mw-collapsed');
// Enable links in this section
$section.find('.mw-headline a').css('pointer-events', 'auto');
// Disable links in all other sections
$sections.not($section).find('.mw-headline a').css('pointer-events', 'none');
} else {
// Collapse this section
$section.addClass('mw-collapsed');
// Disable links in this section
$section.find('.mw-headline a').css('pointer-events', 'none');
}
// Prevent link click from propagating if collapsed
if (e.target.tagName === 'A' && $section.hasClass('mw-collapsed')) {
e.preventDefault();
}
});
});
});