mirror of
https://github.com/google/blockly.git
synced 2026-01-07 00:50:27 +01:00
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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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'.
|
||||
|
||||
Reference in New Issue
Block a user