mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-28 08:10:45 +00:00
42 lines
955 B
JavaScript
42 lines
955 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 === 'until-found' ? false : 'until-found';
|
|
}
|
|
}
|
|
};
|
|
|
|
bodyContent.addEventListener( 'click', handleClick, false );
|
|
}
|
|
|
|
module.exports = {
|
|
init: init
|
|
};
|