mirror of
https://github.com/StarCitizenTools/mediawiki-skins-Citizen.git
synced 2024-11-24 06:24:22 +00:00
refactor: better detection for slash toggle
This commit is contained in:
parent
6264b918e2
commit
74873da01f
|
@ -96,6 +96,24 @@ function focusOnChecked( checkbox, input ) {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if the element is a HTML form element or content editable
|
||||
*
|
||||
* @param {HTMLElement} element
|
||||
* @return {boolean}
|
||||
*/
|
||||
function isFormField( element ) {
|
||||
if ( !( element instanceof HTMLElement ) ) {
|
||||
return false;
|
||||
}
|
||||
const name = element.nodeName.toLowerCase();
|
||||
const type = ( element.getAttribute( 'type') || '' ).toLowerCase();
|
||||
return ( name === 'select' ||
|
||||
name === 'textarea' ||
|
||||
( name === 'input' && type !== 'submit' && type !== 'reset' && type !== 'checkbox' && type !== 'radio' ) ||
|
||||
element.isContentEditable );
|
||||
}
|
||||
|
||||
/**
|
||||
* Manually check the checkbox state when the button is SLASH is pressed.
|
||||
*
|
||||
|
@ -107,11 +125,7 @@ function focusOnChecked( checkbox, input ) {
|
|||
function bindExpandOnSlash( window, checkbox, input ) {
|
||||
const onExpandOnSlash = ( /** @type {KeyboardEvent} */ event ) => {
|
||||
// Only handle SPACE and ENTER.
|
||||
if ( event.key === '/' &&
|
||||
!event.target.matches( 'input' ) &&
|
||||
!event.target.matches( 'textarea' ) &&
|
||||
!document.documentElement.classList.contains( 've-active' )
|
||||
) {
|
||||
if ( event.key === '/' && !isFormField( event.target ) ) {
|
||||
checkbox.checked = true;
|
||||
focusOnChecked( checkbox, input );
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue