From a785ab8d9cceb165e39b1037331e820a7322ce94 Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Tue, 30 Aug 2022 15:49:06 -0400 Subject: [PATCH] fix: remove some IE-specific code in dom and style (#6396) * fix: remove some IE-specific code in dom and style * fix: delete unnecessary getStyle function --- core/utils/dom.ts | 7 ------- core/utils/style.ts | 49 +++++++++++---------------------------------- 2 files changed, 12 insertions(+), 44 deletions(-) diff --git a/core/utils/dom.ts b/core/utils/dom.ts index cdfe3c42e..a74e8cad5 100644 --- a/core/utils/dom.ts +++ b/core/utils/dom.ts @@ -78,13 +78,6 @@ export function createSvgElement( for (const key in attrs) { e.setAttribute(key, attrs[key]); } - // IE defines a unique attribute "runtimeStyle", it is NOT applied to - // elements created with createElementNS. However, Closure checks for IE - // and assumes the presence of the attribute and crashes. - if ((document.body as any) - .runtimeStyle) { // Indicates presence of IE-only attr. - (e as any).runtimeStyle = (e as any).currentStyle = e.style; - } if (opt_parent) { opt_parent.appendChild(e); } diff --git a/core/utils/style.ts b/core/utils/style.ts index caa879ded..6ec94bd58 100644 --- a/core/utils/style.ts +++ b/core/utils/style.ts @@ -14,6 +14,7 @@ import * as goog from '../../closure/goog/goog.js'; goog.declareModuleId('Blockly.utils.style'); +import * as deprecation from './deprecation.js'; import {Coordinate} from './coordinate.js'; import {Rect} from './rect.js'; import {Size} from './size.js'; @@ -35,7 +36,7 @@ export function getSize(element: Element): Size { * Private version of getSize for stubbing in tests. */ function getSizeInternal(element: Element): Size { - if (getStyle(element, 'display') !== 'none') { + if (getComputedStyle(element, 'display') !== 'none') { return getSizeWithDisplay(element); } @@ -74,31 +75,8 @@ function getSizeWithDisplay(element: Element): Size { } /** - * Cross-browser pseudo get computed style. It returns the computed style where - * available. If not available it tries the cascaded style value (IE - * currentStyle) and in worst case the inline style value. It shouldn't be - * called directly, see http://wiki/Main/ComputedStyleVsCascadedStyle for - * discussion. - * - * Copied from Closure's goog.style.getStyle_ - * - * @param element Element to get style of. - * @param style Property to get (must be camelCase, not CSS-style). - * @returns Style value. - */ -function getStyle(element: Element, style: string): string { - // AnyDuringMigration because: Property 'style' does not exist on type - // 'Element'. AnyDuringMigration because: Property 'style' does not exist on - // type 'Element'. - return getComputedStyle(element, style) || getCascadedStyle(element, style) || - (element as AnyDuringMigration).style && - (element as AnyDuringMigration).style[style]; -} - -/** - * Retrieves a computed style value of a node. It returns empty string if the - * value cannot be computed (which will be the case in Internet Explorer) or - * "none" if the property requested is an SVG one and it has not been + * Retrieves a computed style value of a node. It returns empty string + * if the property requested is an SVG one and it has not been * explicitly set (firefox and webkit). * * Copied from Closure's goog.style.getComputedStyle @@ -109,17 +87,11 @@ function getStyle(element: Element, style: string): string { * @alias Blockly.utils.style.getComputedStyle */ export function getComputedStyle(element: Element, property: string): string { - if (document.defaultView && document.defaultView.getComputedStyle) { - const styles = document.defaultView.getComputedStyle(element, null); - if (styles) { - // element.style[..] is undefined for browser specific styles - // as 'filter'. - return (styles as AnyDuringMigration)[property] || - styles.getPropertyValue(property) || ''; - } - } - - return ''; + const styles = window.getComputedStyle(element); + // element.style[..] is undefined for browser specific styles + // as 'filter'. + return (styles as AnyDuringMigration)[property] || + styles.getPropertyValue(property); } /** @@ -134,6 +106,9 @@ export function getComputedStyle(element: Element, property: string): string { * @alias Blockly.utils.style.getCascadedStyle */ export function getCascadedStyle(element: Element, style: string): string { + deprecation.warn( + 'Blockly.utils.style.getCascadedStyle', 'version 9.0.0', + 'version 10.0.0'); // AnyDuringMigration because: Property 'currentStyle' does not exist on type // 'Element'. AnyDuringMigration because: Property 'currentStyle' does not // exist on type 'Element'.