Skip to content

Commit

Permalink
fix: remove some IE-specific code in dom and style (#6396)
Browse files Browse the repository at this point in the history
* fix: remove some IE-specific code in dom and style

* fix: delete unnecessary getStyle function
  • Loading branch information
rachel-fenichel committed Aug 30, 2022
1 parent e6b190c commit a785ab8
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 44 deletions.
7 changes: 0 additions & 7 deletions core/utils/dom.ts
Original file line number Diff line number Diff line change
Expand Up @@ -78,13 +78,6 @@ export function createSvgElement<T extends SVGElement>(
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);
}
Expand Down
49 changes: 12 additions & 37 deletions core/utils/style.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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);
}

Expand Down Expand Up @@ -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
Expand All @@ -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);
}

/**
Expand All @@ -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'.
Expand Down

0 comments on commit a785ab8

Please sign in to comment.