From 056b9e8700b5e4382477bd37929059adfe128bed Mon Sep 17 00:00:00 2001 From: Popov Aleksey Date: Tue, 12 Sep 2023 05:59:02 -0700 Subject: [PATCH] refactor: removed IE leftovers from src\client\core (#8000) ## Purpose _Describe the problem you want to address or the feature you want to implement._ ## Approach _Describe how your changes address the issue or implement the desired functionality in as much detail as possible._ ## References _Provide a link to the existing issue(s), if any._ ## Pre-Merge TODO - [ ] Write tests for your proposed changes - [ ] Make sure that existing tests do not fail --- src/client/core/prevent-real-events.js | 48 +++++--------------------- src/client/core/utils/dom.js | 42 +++++----------------- 2 files changed, 18 insertions(+), 72 deletions(-) diff --git a/src/client/core/prevent-real-events.js b/src/client/core/prevent-real-events.js index ccbc9cec8ba..c315c5e4cfb 100644 --- a/src/client/core/prevent-real-events.js +++ b/src/client/core/prevent-real-events.js @@ -6,17 +6,11 @@ import { import scrollController from './scroll/controller'; -import { get, hasDimensions } from './utils/style'; -import { filter } from './utils/array'; -import { - isShadowUIElement, - isWindow, - getParents, -} from './utils/dom'; +import { hasDimensions } from './utils/style'; +import { isShadowUIElement } from './utils/dom'; -const browserUtils = utils.browser; -const listeners = eventSandbox.listeners; -const eventSimulator = eventSandbox.eventSimulator; +const browserUtils = utils.browser; +const listeners = eventSandbox.listeners; const PREVENTED_EVENTS = [ 'click', 'mousedown', 'mouseup', 'dblclick', 'contextmenu', 'mousemove', 'mouseover', 'mouseout', @@ -47,35 +41,11 @@ function preventRealEventHandler (e, dispatched, preventDefault, cancelHandlers, } // NOTE: if an element loses focus because of becoming invisible, the blur event is - // raised. We must not prevent this blur event. In IE, an element loses focus only - // if the CSS 'display' property is set to 'none', other ways of making an element - // invisible don't lead to blurring (in MSEdge, focus/blur are sync). - if (e.type === 'blur') { - if (browserUtils.isIE && browserUtils.version < 12) { - const isWindowInstance = isWindow(target); - const isElementInvisible = !isWindowInstance && get(target, 'display') === 'none'; - let elementParents = null; - let invisibleParents = false; - - if (!isWindowInstance && !isElementInvisible) { - elementParents = getParents(target); - invisibleParents = filter(elementParents, parent => get(parent, 'display') === 'none'); - } - - if (isElementInvisible || invisibleParents.length) { - // NOTE: In IE we should prevent the event and raise it on timeout. This is a fix for - // the case when a focus event leads to the element disappearing. If we don't prevent - // the blur event it will be raised before the previous focus event is raised (see B254768) - eventSandbox.timers.deferFunction(() => { - eventSimulator.blur(target); - }); - } - } - // NOTE: fix for a jQuery bug. An exception is raised when calling .is(':visible') - // for a window or document on page loading (when e.ownerDocument is null). - else if (target !== window && target !== window.document && !hasDimensions(target)) - return; - } + // raised. We must not prevent this blur event. + // NOTE: fix for a jQuery bug. An exception is raised when calling .is(':visible') + // for a window or document on page loading (when e.ownerDocument is null). + if (e.type === 'blur' && target !== window && target !== window.document && !hasDimensions(target)) + return; preventDefault(); } diff --git a/src/client/core/utils/dom.js b/src/client/core/utils/dom.js index 80eb168f08c..d3ce9985cd0 100644 --- a/src/client/core/utils/dom.js +++ b/src/client/core/utils/dom.js @@ -40,7 +40,6 @@ export const isMapElement = hammerhead.utils.dom.isMap export const isBodyElement = hammerhead.utils.dom.isBodyElement; export const isHtmlElement = hammerhead.utils.dom.isHtmlElement; export const isDocument = hammerhead.utils.dom.isDocument; -export const isWindow = hammerhead.utils.dom.isWindow; export const isTextEditableInput = hammerhead.utils.dom.isTextEditableInput; export const isTextEditableElement = hammerhead.utils.dom.isTextEditableElement; export const isTextEditableElementAndEditingAllowed = hammerhead.utils.dom.isTextEditableElementAndEditingAllowed; @@ -75,7 +74,7 @@ function canFocus (element, parent, tabIndex) { if (getElementStyleProperty(element, 'display') === 'none' || getElementStyleProperty(element, 'visibility') === 'hidden') return false; - if ((browserUtils.isIE || browserUtils.isAndroid) && isOptionElement(element)) + if (browserUtils.isAndroid && isOptionElement(element)) return false; if (tabIndex !== null && tabIndex < 0) @@ -127,33 +126,23 @@ function filterFocusableElements (parent) { let tagName = null; let tabIndex = null; - let needPush = false; - for (let i = 0; i < allElements.length; i++) { element = allElements[i]; tagName = getTagName(element); tabIndex = getTabIndexAttributeIntValue(element); - needPush = false; if (!canFocus(element, parent, tabIndex)) continue; - if (inputElementsRegExp.test(tagName)) - needPush = true; - else if (element.shadowRoot) - needPush = true; - else if (isIframeElement(element)) - needPush = true; - else if (isAnchorElement(element) && element.hasAttribute('href')) - needPush = element.getAttribute('href') !== '' || !browserUtils.isIE || tabIndex !== null; - const contentEditableAttr = element.getAttribute('contenteditable'); - if (contentEditableAttr === '' || contentEditableAttr === 'true') - needPush = true; - - if (tabIndex !== null) - needPush = true; + const needPush = inputElementsRegExp.test(tagName) + || element.shadowRoot + || isIframeElement(element) + || isAnchorElement(element) && element.hasAttribute('href') + || contentEditableAttr === '' + || contentEditableAttr === 'true' + || tabIndex !== null; if (needPush) focusableElements.push(element); @@ -265,8 +254,6 @@ export function blocksImplicitSubmission (el) { inputTypeRegExp = /^(text|password|color|date|time|datetime|datetime-local|email|month|number|search|tel|url|week|image)$/i; else if (browserUtils.isFirefox) inputTypeRegExp = /^(text|password|date|time|datetime|datetime-local|email|month|number|search|tel|url|week|image)$/i; - else if (browserUtils.isIE) - inputTypeRegExp = /^(text|password|color|date|time|datetime|datetime-local|email|file|month|number|search|tel|url|week|image)$/i; else inputTypeRegExp = /^(text|password|datetime|email|number|search|tel|url|image)$/i; @@ -358,11 +345,6 @@ export function remove (el) { } export function isIFrameWindowInDOM (win) { - //NOTE: In MS Edge, if an iframe is removed from DOM, the browser throws an exception when accessing window.top - //and window.frameElement. Fortunately, setTimeout is set to undefined in this case. - if (!win.setTimeout) - return false; - let frameElement = null; try { @@ -382,13 +364,7 @@ export function isIFrameWindowInDOM (win) { } export function isTopWindow (win) { - try { - //NOTE: MS Edge throws an exception when trying to access window.top from an iframe removed from DOM - return win.top === win; - } - catch (e) { - return false; - } + return win.top === win; } export function findIframeByWindow (iframeWindow) {