Some goog.dom removal (#1991)

This commit is contained in:
Neil Fraser
2018-08-01 15:47:28 -07:00
committed by GitHub
parent 1fa4a8d856
commit 6ce31942e0
5 changed files with 22 additions and 9 deletions

View File

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

View File

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

View File

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

View File

@@ -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');

View File

@@ -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_);