diff --git a/core/inject.js b/core/inject.js index 46289275ec2..312bfbb537f 100644 --- a/core/inject.js +++ b/core/inject.js @@ -34,7 +34,6 @@ goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceSvg'); goog.require('Blockly.WorkspaceDragSurfaceSvg'); -goog.require('goog.dom'); goog.require('goog.ui.Component'); goog.require('goog.userAgent'); @@ -54,7 +53,7 @@ Blockly.inject = function(container, opt_options) { document.querySelector(container); } // Verify that the container is in document. - if (!goog.dom.contains(document, container)) { + if (!Blockly.utils.containsNode(document, container)) { throw Error('Error: container is not in current document.'); } var options = new Blockly.Options(opt_options || {}); diff --git a/core/toolbox.js b/core/toolbox.js index 6546d4a060d..e25f17d8407 100644 --- a/core/toolbox.js +++ b/core/toolbox.js @@ -33,7 +33,6 @@ goog.require('Blockly.Touch'); goog.require('Blockly.utils'); goog.require('Blockly.VerticalFlyout'); -goog.require('goog.dom'); goog.require('goog.events'); goog.require('goog.events.BrowserFeature'); goog.require('goog.html.SafeHtml'); @@ -191,8 +190,10 @@ Blockly.Toolbox.prototype.init = function() { } else { this.flyout_ = new Blockly.VerticalFlyout(workspaceOptions); } - goog.dom.insertSiblingAfter( - this.flyout_.createDom('svg'), this.workspace_.getParentSvg()); + // Insert the flyout after the workspace. + var workspaceSvg = this.workspace_.getParentSvg(); + workspaceSvg.parentNode.insertBefore(this.flyout_.createDom('svg'), + workspaceSvg.nextSibling); this.flyout_.init(workspace); this.config_['cleardotPath'] = workspace.options.pathToMedia + '1x1.gif'; diff --git a/core/utils.js b/core/utils.js index cd0e9881800..f28f0fcb722 100644 --- a/core/utils.js +++ b/core/utils.js @@ -946,3 +946,14 @@ Blockly.utils.toRadians = function(angleDegrees) { Blockly.utils.toDegrees = function(angleRadians) { return angleRadians * 180 / Math.PI; }; + +/** + * Whether a node contains another node. + * @param {!Node} parent The node that should contain the other node. + * @param {!Node} descendant The node to test presence of. + * @return {boolean} Whether the parent node contains the descendant node. + */ +Blockly.utils.containsNode = function(parent, descendant) { + return !!(parent.compareDocumentPosition(descendant) & + Node.DOCUMENT_POSITION_CONTAINED_BY); +}; diff --git a/core/workspace_comment_svg.js b/core/workspace_comment_svg.js index 9205ad350de..6f5e8ea0d2e 100644 --- a/core/workspace_comment_svg.js +++ b/core/workspace_comment_svg.js @@ -32,7 +32,6 @@ goog.require('Blockly.Events.CommentMove'); goog.require('Blockly.utils'); goog.require('Blockly.WorkspaceComment'); -goog.require('goog.dom'); goog.require('goog.math.Coordinate'); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index cd9e51dff31..7f4d2a5eb29 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -346,8 +346,8 @@ Blockly.WorkspaceSvg.prototype.getSvgXY = function(element) { var x = 0; var y = 0; var scale = 1; - if (goog.dom.contains(this.getCanvas(), element) || - goog.dom.contains(this.getBubbleCanvas(), element)) { + if (Blockly.utils.containsNode(this.getCanvas(), element) || + Blockly.utils.containsNode(this.getBubbleCanvas(), element)) { // Before the SVG canvas, scale the coordinates. scale = this.scale; } @@ -539,7 +539,10 @@ Blockly.WorkspaceSvg.prototype.dispose = function() { if (!this.options.parentWorkspace) { // Top-most workspace. Dispose of the div that the // SVG is injected into (i.e. injectionDiv). - goog.dom.removeNode(this.getParentSvg().parentNode); + var div = this.getParentSvg().parentNode; + if (div) { + div.parentNode.removeChild(div); + } } if (this.resizeHandlerWrapper_) { Blockly.unbindEvent_(this.resizeHandlerWrapper_);