From 92f388000801e5a67aad093ef578b6e930b5840b Mon Sep 17 00:00:00 2001 From: Rachel Fenichel Date: Mon, 27 Mar 2017 17:25:41 -0700 Subject: [PATCH] RemoveAttribute doesn't work on SVG elements in IE 10. Use setAttribute to null instead. --- core/block_svg.js | 7 ++++--- core/utils.js | 19 ++++++++++++++++++- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/core/block_svg.js b/core/block_svg.js index 7fc41293d51..d8edb1097d0 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -28,8 +28,9 @@ goog.provide('Blockly.BlockSvg'); goog.require('Blockly.Block'); goog.require('Blockly.ContextMenu'); -goog.require('Blockly.Touch'); goog.require('Blockly.RenderedConnection'); +goog.require('Blockly.Touch'); +goog.require('Blockly.utils'); goog.require('goog.Timer'); goog.require('goog.asserts'); goog.require('goog.dom'); @@ -425,7 +426,7 @@ Blockly.BlockSvg.prototype.moveOffDragSurface_ = function() { * @private */ Blockly.BlockSvg.prototype.clearTransformAttributes_ = function() { - this.getSvgRoot().removeAttribute('transform'); + Blockly.utils.removeAttribute(this.getSvgRoot(), 'transform'); }; /** @@ -1569,7 +1570,7 @@ Blockly.BlockSvg.prototype.setHighlighted = function(highlighted) { 'url(#' + this.workspace.options.embossFilterId + ')'); this.svgPathLight_.style.display = 'none'; } else { - this.svgPath_.removeAttribute('filter'); + Blockly.utils.removeAttribute(this.svgPath_, 'filter'); delete this.svgPathLight_.style.display; } }; diff --git a/core/utils.js b/core/utils.js index 641bb742ca6..464fd0e3a64 100644 --- a/core/utils.js +++ b/core/utils.js @@ -38,6 +38,23 @@ goog.require('goog.events.BrowserFeature'); goog.require('goog.math.Coordinate'); goog.require('goog.userAgent'); +/** + * Remove an attribute from a element even if it's in IE 10. + * Similar to Element.removeAttribute() but it works on SVG elements in IE 10. + * Sets the attribute to null in IE 10, which treats removeAttribute as a no-op + * if it's called on an SVG element. + * @param {!Element} element DOM element to remove attribute from. + * @param {string} attributeName Name of attribute to remove. + */ +Blockly.utils.removeAttribute = function(element, attributeName) { + // goog.userAgent.isVersion is deprecated, but the replacement is + // goog.userAgent.isVersionOrHigher. + if (goog.userAgent.IE && goog.userAgent.isVersion('10.0')) { + element.setAttribute(attributeName, null); + } else { + element.removeAttribute(attributeName); + } +}; /** * Add a CSS class to a element. @@ -80,7 +97,7 @@ Blockly.utils.removeClass = function(element, className) { if (classList.length) { element.setAttribute('class', classList.join(' ')); } else { - element.removeAttribute('class'); + Blockly.utils.removeAttribute(element, 'class'); } return true; };