Skip to content

Commit

Permalink
RemoveAttribute doesn't work on SVG elements in IE 10. Use setAttribu…
Browse files Browse the repository at this point in the history
…te to null instead.
  • Loading branch information
rachel-fenichel committed Mar 28, 2017
1 parent b0856b8 commit 92f3880
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 4 deletions.
7 changes: 4 additions & 3 deletions core/block_svg.js
Expand Up @@ -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');
Expand Down Expand Up @@ -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');
};

/**
Expand Down Expand Up @@ -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;
}
};
Expand Down
19 changes: 18 additions & 1 deletion core/utils.js
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
};
Expand Down

0 comments on commit 92f3880

Please sign in to comment.