Merge pull request from rachel-fenichel/merge_cleanup_1

Utility function cleanup for merges
This commit is contained in:
Andrew Sliwinski 2018-10-25 08:52:11 -04:00 committed by GitHub
commit 1e750d5b60
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
10 changed files with 22 additions and 16 deletions

View file

@ -83,6 +83,11 @@ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) {
Blockly.Tooltip.bindMouseEvents(this.svgPath_); Blockly.Tooltip.bindMouseEvents(this.svgPath_);
Blockly.BlockSvg.superClass_.constructor.call(this, Blockly.BlockSvg.superClass_.constructor.call(this,
workspace, prototypeName, opt_id); workspace, prototypeName, opt_id);
// Expose this block's ID on its top-level SVG group.
if (this.svgGroup_.dataset) {
this.svgGroup_.dataset.id = this.id;
}
}; };
goog.inherits(Blockly.BlockSvg, Blockly.Block); goog.inherits(Blockly.BlockSvg, Blockly.Block);

View file

@ -29,7 +29,6 @@ goog.provide('Blockly.Bubble');
goog.require('Blockly.Touch'); goog.require('Blockly.Touch');
goog.require('Blockly.Workspace'); goog.require('Blockly.Workspace');
goog.require('goog.dom'); goog.require('goog.dom');
goog.require('goog.math');
goog.require('goog.math.Coordinate'); goog.require('goog.math.Coordinate');
goog.require('goog.userAgent'); goog.require('goog.userAgent');
@ -56,7 +55,7 @@ Blockly.Bubble = function(workspace, content, shape, anchorXY,
if (this.workspace_.RTL) { if (this.workspace_.RTL) {
angle = -angle; angle = -angle;
} }
this.arrow_radians_ = goog.math.toRadians(angle); this.arrow_radians_ = Blockly.utils.toRadians(angle);
var canvas = workspace.getBubbleCanvas(); var canvas = workspace.getBubbleCanvas();
canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight))); canvas.appendChild(this.createDom_(content, !!(bubbleWidth && bubbleHeight)));

View file

@ -159,7 +159,7 @@ Blockly.BubbleDragger.prototype.maybeDeleteBubble_ = function() {
if (this.wouldDeleteBubble_) { if (this.wouldDeleteBubble_) {
if (trashcan) { if (trashcan) {
goog.Timer.callOnce(trashcan.close, 100, trashcan); setTimeout(trashcan.close.bind(trashcan), 100);
} }
// Fire a move event, so we know where to go back to for an undo. // Fire a move event, so we know where to go back to for an undo.
this.fireMoveEvent_(); this.fireMoveEvent_();

View file

@ -199,6 +199,8 @@ Blockly.Comment.prototype.setVisible = function(visible) {
/** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace), /** @type {!Blockly.WorkspaceSvg} */ (this.block_.workspace),
this.createEditor_(), this.block_.svgPath_, this.createEditor_(), this.block_.svgPath_,
this.iconXY_, this.width_, this.height_); this.iconXY_, this.width_, this.height_);
// Expose this comment's block's ID on its top-level SVG group.
this.bubble_.setSvgId(this.block_.id);
this.bubble_.registerResizeEvent(this.resizeBubble_.bind(this)); this.bubble_.registerResizeEvent(this.resizeBubble_.bind(this));
this.updateColour(); this.updateColour();
} else { } else {

View file

@ -281,7 +281,7 @@ Blockly.createMainWorkspace_ = function(svg, options, blockDragSurface, workspac
if (!options.hasCategories && options.languageTree) { if (!options.hasCategories && options.languageTree) {
// Add flyout as an <svg> that is a sibling of the workspace svg. // Add flyout as an <svg> that is a sibling of the workspace svg.
var flyout = mainWorkspace.addFlyout_('svg'); var flyout = mainWorkspace.addFlyout_('svg');
Blockly.utils.insertAfter_(flyout, svg); Blockly.utils.insertAfter(flyout, svg);
} }
// A null translation will also apply the correct initial scale. // A null translation will also apply the correct initial scale.

View file

@ -55,7 +55,7 @@ Blockly.ScrollbarPair = function(workspace) {
'class': 'blocklyScrollbarBackground' 'class': 'blocklyScrollbarBackground'
}, },
null); null);
Blockly.utils.insertAfter_(this.corner_, workspace.getBubbleCanvas()); Blockly.utils.insertAfter(this.corner_, workspace.getBubbleCanvas());
}; };
/** /**
@ -625,7 +625,7 @@ Blockly.Scrollbar.prototype.createDom_ = function(opt_class) {
'ry': radius 'ry': radius
}, },
this.svgGroup_); this.svgGroup_);
Blockly.utils.insertAfter_(this.outerSvg_, this.workspace_.getParentSvg()); Blockly.utils.insertAfter(this.outerSvg_, this.workspace_.getParentSvg());
}; };
/** /**

View file

@ -180,7 +180,7 @@ Blockly.Touch.checkTouchIdentifier = function(e) {
* @param {!Event} e A touch event. * @param {!Event} e A touch event.
*/ */
Blockly.Touch.setClientFromTouch = function(e) { Blockly.Touch.setClientFromTouch = function(e) {
if (goog.string.startsWith(e.type, 'touch')) { if (Blockly.utils.startsWith(e.type, 'touch')) {
// Map the touch event's properties to the event. // Map the touch event's properties to the event.
var touchPoint = e.changedTouches[0]; var touchPoint = e.changedTouches[0];
e.clientX = touchPoint.clientX; e.clientX = touchPoint.clientX;
@ -194,8 +194,8 @@ Blockly.Touch.setClientFromTouch = function(e) {
* @return {boolean} true if it is a mouse or touch event; false otherwise. * @return {boolean} true if it is a mouse or touch event; false otherwise.
*/ */
Blockly.Touch.isMouseOrTouchEvent = function(e) { Blockly.Touch.isMouseOrTouchEvent = function(e) {
return goog.string.startsWith(e.type, 'touch') || return Blockly.utils.startsWith(e.type, 'touch') ||
goog.string.startsWith(e.type, 'mouse'); Blockly.utils.startsWith(e.type, 'mouse');
}; };
/** /**

View file

@ -27,7 +27,6 @@
goog.provide('Blockly.Trashcan'); goog.provide('Blockly.Trashcan');
goog.require('goog.dom'); goog.require('goog.dom');
goog.require('goog.math');
goog.require('goog.math.Rect'); goog.require('goog.math.Rect');
@ -309,13 +308,14 @@ Blockly.Trashcan.prototype.setOpen_ = function(state) {
*/ */
Blockly.Trashcan.prototype.animateLid_ = function() { Blockly.Trashcan.prototype.animateLid_ = function() {
this.lidOpen_ += this.isOpen ? 0.2 : -0.2; this.lidOpen_ += this.isOpen ? 0.2 : -0.2;
this.lidOpen_ = goog.math.clamp(this.lidOpen_, 0, 1); this.lidOpen_ = Math.min(Math.max(this.lidOpen_, 0), 1);
var lidAngle = this.lidOpen_ * 45; var lidAngle = this.lidOpen_ * 45;
this.svgLid_.setAttribute('transform', 'rotate(' + this.svgLid_.setAttribute('transform', 'rotate(' +
(this.workspace_.RTL ? -lidAngle : lidAngle) + ',' + (this.workspace_.RTL ? -lidAngle : lidAngle) + ',' +
(this.workspace_.RTL ? 4 : this.WIDTH_ - 4) + ',' + (this.workspace_.RTL ? 4 : this.WIDTH_ - 4) + ',' +
(this.LID_HEIGHT_ - 2) + ')'); (this.LID_HEIGHT_ - 2) + ')');
var opacity = goog.math.lerp(0.4, 0.8, this.lidOpen_); // Linear interpolation between 0.4 and 0.8.
var opacity = 0.4 + this.lidOpen_ * (0.8 - 0.4);
this.svgGroup_.style.opacity = opacity; this.svgGroup_.style.opacity = opacity;
if (this.lidOpen_ > 0 && this.lidOpen_ < 1) { if (this.lidOpen_ > 0 && this.lidOpen_ < 1) {
this.lidTask_ = setTimeout(this.animateLid_.bind(this), 20); this.lidTask_ = setTimeout(this.animateLid_.bind(this), 20);

View file

@ -867,9 +867,9 @@ Blockly.utils.is3dSupported = function() {
* Contrast with node.insertBefore function. * Contrast with node.insertBefore function.
* @param {!Element} newNode New element to insert. * @param {!Element} newNode New element to insert.
* @param {!Element} refNode Existing element to precede new node. * @param {!Element} refNode Existing element to precede new node.
* @private * @package
*/ */
Blockly.utils.insertAfter_ = function(newNode, refNode) { Blockly.utils.insertAfter = function(newNode, refNode) {
var siblingNode = refNode.nextSibling; var siblingNode = refNode.nextSibling;
var parentNode = refNode.parentNode; var parentNode = refNode.parentNode;
if (!parentNode) { if (!parentNode) {

View file

@ -151,13 +151,13 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
// If there is a previous sibling, put the blockCanvas back right afterwards, // If there is a previous sibling, put the blockCanvas back right afterwards,
// otherwise insert it as the first child node in newSurface. // otherwise insert it as the first child node in newSurface.
if (this.previousSibling_ != null) { if (this.previousSibling_ != null) {
Blockly.utils.insertAfter_(blockCanvas, this.previousSibling_); Blockly.utils.insertAfter(blockCanvas, this.previousSibling_);
} else { } else {
newSurface.insertBefore(blockCanvas, newSurface.firstChild); newSurface.insertBefore(blockCanvas, newSurface.firstChild);
} }
// Reattach the bubble canvas after the blockCanvas. // Reattach the bubble canvas after the blockCanvas.
Blockly.utils.insertAfter_(bubbleCanvas, blockCanvas); Blockly.utils.insertAfter(bubbleCanvas, blockCanvas);
// Hide the drag surface. // Hide the drag surface.
this.SVG_.style.display = 'none'; this.SVG_.style.display = 'none';
goog.asserts.assert( goog.asserts.assert(