mediawiki-skins-MinervaNeue/includes/Skins/ToggleList/ToggleList.js
Fomafix bc81b04ecd Remove redundant closure for all modules with packageFiles
Modules loaded with packageFiles are always executed in module scope
(with a closure), even in debug mode.

The behaviour of non-packageFiles debug mode is the only reason files
have closures.

https://www.mediawiki.org/wiki/Manual:Coding_conventions/JavaScript#Closure

Change-Id: I14ac680eb67d892618bbc13be9298ec9b8e0e2e9
2024-11-07 08:39:58 -08:00

33 lines
1,023 B
JavaScript

const
checkboxHack = require( ( 'mediawiki.page.ready' ) ).checkboxHack,
CHECKBOX_HACK_CONTAINER_SELECTOR = '.toggle-list',
CHECKBOX_HACK_CHECKBOX_SELECTOR = '.toggle-list__checkbox',
CHECKBOX_HACK_BUTTON_SELECTOR = '.toggle-list__toggle',
CHECKBOX_HACK_TARGET_SELECTOR = '.toggle-list__list';
/**
* Automatically dismiss the list when clicking or focusing elsewhere and update the
* aria-expanded attribute based on list visibility.
*
* @param {Window} window
* @param {HTMLElement} component
*/
function bind( window, component ) {
const
checkbox = /** @type {HTMLInputElement} */ (
component.querySelector( CHECKBOX_HACK_CHECKBOX_SELECTOR )
),
button = component.querySelector( CHECKBOX_HACK_BUTTON_SELECTOR ),
target = component.querySelector( CHECKBOX_HACK_TARGET_SELECTOR ).parentNode;
if ( !( checkbox && button && target ) ) {
return;
}
checkboxHack.bind( window, checkbox, button, target );
}
module.exports = Object.freeze( {
selector: CHECKBOX_HACK_CONTAINER_SELECTOR,
bind
} );