fix: allow checkbox button to uncheck when clicked

This commit is contained in:
alistair3149 2021-01-21 21:43:20 -05:00
parent 98c6bb244e
commit 2836831335
No known key found for this signature in database
GPG key ID: 94D081060FD3DD9C

View file

@ -1,18 +1,23 @@
var DRAWER_ID = 'mw-drawer', var DRAWER_ID = 'mw-drawer',
DRAWER_BUTTON_ID = 'mw-drawer-button',
DRAWER_CHECKBOX_ID = 'mw-drawer-checkbox', DRAWER_CHECKBOX_ID = 'mw-drawer-checkbox',
PERSONAL_MENU_ID = 'p-personal', PERSONAL_MENU_ID = 'p-personal',
PERSONAL_MENU_BUTTON_ID = 'personalmenu-button',
PERSONAL_MENU_CHECKBOX_ID = 'personalmenu-checkbox'; PERSONAL_MENU_CHECKBOX_ID = 'personalmenu-checkbox';
/** /**
* Uncheck CSS hack checkbox when clicked outside * Uncheck CSS hack checkbox when clicked outside
* *
* @param {HTMLElement} element * @param {HTMLElement} element
* @param {HTMLElement} button
* @param {HTMLElement} checkbox * @param {HTMLElement} checkbox
*/ */
function uncheckOnClickOutside( element, checkbox ) { function uncheckOnClickOutside( element, button, checkbox ) {
var listener = function ( e ) { var listener = function ( e ) {
if ( e.target !== checkbox && e.target !== element ) { if ( e.target !== checkbox && e.target !== element ) {
checkbox.checked = false; if ( e.target !== button ) {
checkbox.checked = false;
}
document.removeEventListener( 'click', listener ); document.removeEventListener( 'click', listener );
} }
}; };
@ -28,11 +33,13 @@ function uncheckOnClickOutside( element, checkbox ) {
*/ */
function init() { function init() {
var drawer = document.getElementById( DRAWER_ID ), var drawer = document.getElementById( DRAWER_ID ),
drawerButton = document.getElementById( DRAWER_BUTTON_ID ),
drawerCheckbox = document.getElementById( DRAWER_CHECKBOX_ID ), drawerCheckbox = document.getElementById( DRAWER_CHECKBOX_ID ),
personalMenu = document.getElementById( PERSONAL_MENU_ID ), personalMenu = document.getElementById( PERSONAL_MENU_ID ),
personalMenuButton = document.getElementById( PERSONAL_MENU_BUTTON_ID ),
personalMenuCheckbox = document.getElementById( PERSONAL_MENU_CHECKBOX_ID ); personalMenuCheckbox = document.getElementById( PERSONAL_MENU_CHECKBOX_ID );
uncheckOnClickOutside( drawer, drawerCheckbox ); uncheckOnClickOutside( drawer, drawerButton, drawerCheckbox );
uncheckOnClickOutside( personalMenu, personalMenuCheckbox ); uncheckOnClickOutside( personalMenu, personalMenuButton, personalMenuCheckbox );
} }
module.exports = { module.exports = {