From da6cff95e398bd81021f2d925d6db304855a391a Mon Sep 17 00:00:00 2001 From: Sebastian Silbermann Date: Thu, 25 Apr 2019 12:43:26 +0000 Subject: [PATCH] Remove initial handlers --- src/focus-visible.js | 50 -------------------------------------------- 1 file changed, 50 deletions(-) diff --git a/src/focus-visible.js b/src/focus-visible.js index 83cd8c7..5e65c29 100644 --- a/src/focus-visible.js +++ b/src/focus-visible.js @@ -178,58 +178,9 @@ function init() { if (hadFocusVisibleRecently) { hadKeyboardEvent = true; } - addInitialPointerMoveListeners(); } } - /** - * Add a group of listeners to detect usage of any pointing devices. - * These listeners will be added when the polyfill first loads, and anytime - * the window is blurred, so that they are active when the window regains - * focus. - */ - function addInitialPointerMoveListeners() { - document.addEventListener('mousemove', onInitialPointerMove); - document.addEventListener('mousedown', onInitialPointerMove); - document.addEventListener('mouseup', onInitialPointerMove); - document.addEventListener('pointermove', onInitialPointerMove); - document.addEventListener('pointerdown', onInitialPointerMove); - document.addEventListener('pointerup', onInitialPointerMove); - document.addEventListener('touchmove', onInitialPointerMove); - document.addEventListener('touchstart', onInitialPointerMove); - document.addEventListener('touchend', onInitialPointerMove); - } - - function removeInitialPointerMoveListeners() { - document.removeEventListener('mousemove', onInitialPointerMove); - document.removeEventListener('mousedown', onInitialPointerMove); - document.removeEventListener('mouseup', onInitialPointerMove); - document.removeEventListener('pointermove', onInitialPointerMove); - document.removeEventListener('pointerdown', onInitialPointerMove); - document.removeEventListener('pointerup', onInitialPointerMove); - document.removeEventListener('touchmove', onInitialPointerMove); - document.removeEventListener('touchstart', onInitialPointerMove); - document.removeEventListener('touchend', onInitialPointerMove); - } - - /** - * When the polfyill first loads, assume the user is in keyboard modality. - * If any event is received from a pointing device (e.g. mouse, pointer, - * touch), turn off keyboard modality. - * This accounts for situations where focus enters the page from the URL bar. - * @param {Event} e - */ - function onInitialPointerMove(e) { - // Work around a Safari quirk that fires a mousemove on whenever the - // window blurs, even if you're tabbing out of the page. ¯\_(ツ)_/¯ - if (e.target.nodeName.toLowerCase() === 'html') { - return; - } - - hadKeyboardEvent = false; - removeInitialPointerMoveListeners(); - } - document.addEventListener('keydown', onKeyDown, true); document.addEventListener('mousedown', onPointerDown, true); document.addEventListener('pointerdown', onPointerDown, true); @@ -237,7 +188,6 @@ function init() { document.addEventListener('focus', onFocus, true); document.addEventListener('blur', onBlur, true); document.addEventListener('visibilitychange', onVisibilityChange, true); - addInitialPointerMoveListeners(); document.body.classList.add('js-focus-visible'); }