Skip to content

Commit

Permalink
Some goog.dom removal (#1991)
Browse files Browse the repository at this point in the history
  • Loading branch information
NeilFraser authored Aug 1, 2018
1 parent 1fa4a8d commit 6ce3194
Show file tree
Hide file tree
Showing 5 changed files with 22 additions and 9 deletions.
3 changes: 1 addition & 2 deletions core/inject.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand All @@ -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 || {});
Expand Down
7 changes: 4 additions & 3 deletions core/toolbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -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';
Expand Down
11 changes: 11 additions & 0 deletions core/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
};
1 change: 0 additions & 1 deletion core/workspace_comment_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');


Expand Down
9 changes: 6 additions & 3 deletions core/workspace_svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -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_);
Expand Down

0 comments on commit 6ce3194

Please sign in to comment.