Merge pull request #1005 from rachel-fenichel/bugfix/IE10_offsets

RemoveAttribute doesn't work on SVG elements in IE 10.  Use setAttrib…
This commit is contained in:
Rachel Fenichel
2017-03-28 09:06:23 -07:00
committed by GitHub
2 changed files with 22 additions and 4 deletions

View File

@@ -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;
}
};

View File

@@ -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;
};