2021-04-21 01:04:08 +00:00
|
|
|
/**
|
2023-04-30 22:01:53 +00:00
|
|
|
* Set up functionality of collapsable sections
|
|
|
|
*
|
|
|
|
* @param {HTMLElement} bodyContent
|
2021-04-21 01:04:08 +00:00
|
|
|
* @return {void}
|
|
|
|
*/
|
2023-04-30 22:01:53 +00:00
|
|
|
function init( bodyContent ) {
|
|
|
|
if ( !document.body.classList.contains( 'citizen-sections-enabled' ) ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-05-21 22:46:19 +00:00
|
|
|
const onEditSectionClick = ( e ) => {
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
2023-06-20 18:29:37 +00:00
|
|
|
|
2024-05-21 22:46:19 +00:00
|
|
|
const handleClick = ( e ) => {
|
|
|
|
const target = e.target;
|
|
|
|
const isEditSection = target.closest( '.mw-editsection, .mw-editsection-like' );
|
|
|
|
|
|
|
|
if ( isEditSection ) {
|
|
|
|
onEditSectionClick( e );
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2024-10-16 20:17:32 +00:00
|
|
|
const heading = target.closest( '.citizen-section-heading' );
|
2024-05-21 22:46:19 +00:00
|
|
|
|
2024-10-16 20:17:32 +00:00
|
|
|
if ( heading && heading.nextElementSibling && heading.nextElementSibling.classList.contains( 'citizen-section' ) ) {
|
|
|
|
const section = heading.nextElementSibling;
|
2024-05-21 22:46:19 +00:00
|
|
|
|
2024-10-16 20:17:32 +00:00
|
|
|
if ( section ) {
|
2024-10-25 18:06:52 +00:00
|
|
|
section.hidden = section.hidden ? false : 'until-found';
|
2024-05-21 22:46:19 +00:00
|
|
|
}
|
2024-05-21 22:08:28 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2024-05-21 22:46:19 +00:00
|
|
|
bodyContent.addEventListener( 'click', handleClick, false );
|
2021-04-21 01:04:08 +00:00
|
|
|
}
|
|
|
|
|
2022-12-09 19:48:17 +00:00
|
|
|
module.exports = {
|
2023-04-30 22:01:53 +00:00
|
|
|
init: init
|
2022-12-09 19:48:17 +00:00
|
|
|
};
|