mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-12-11 14:06:33 +00:00
42 lines
937 B
JavaScript
42 lines
937 B
JavaScript
/**
|
|
* Set up functionality of collapsable sections
|
|
*
|
|
* @param {HTMLElement} bodyContent
|
|
* @return {void}
|
|
*/
|
|
function init( bodyContent ) {
|
|
if ( !document.body.classList.contains( 'citizen-sections-enabled' ) ) {
|
|
return;
|
|
}
|
|
|
|
const onEditSectionClick = ( e ) => {
|
|
e.stopPropagation();
|
|
};
|
|
|
|
const handleClick = ( e ) => {
|
|
const target = e.target;
|
|
const isEditSection = target.closest( '.mw-editsection, .mw-editsection-like' );
|
|
|
|
if ( isEditSection ) {
|
|
onEditSectionClick( e );
|
|
return;
|
|
}
|
|
|
|
const heading = target.closest( '.citizen-section-heading' );
|
|
|
|
if ( heading && heading.nextElementSibling && heading.nextElementSibling.classList.contains( 'citizen-section' ) ) {
|
|
const section = heading.nextElementSibling;
|
|
|
|
if ( section ) {
|
|
section.hidden = section.hidden ? false : 'until-found';
|
|
}
|
|
}
|
|
};
|
|
|
|
bodyContent.addEventListener( 'click', handleClick, false );
|
|
}
|
|
|
|
module.exports = {
|
|
init: init
|
|
};
|