From 8cedef49ac73de98a5d17a020c0013fb31c36207 Mon Sep 17 00:00:00 2001 From: Neil Fraser Date: Mon, 6 Nov 2017 14:50:51 -0800 Subject: [PATCH] Cleanup. --- core/block_drag_surface.js | 6 +++--- core/block_render_svg.js | 21 +++++++++------------ core/block_svg.js | 21 ++++++++++----------- core/flyout_button.js | 11 +++++------ core/inject.js | 2 +- core/scrollbar.js | 6 +++--- core/workspace_drag_surface_svg.js | 6 +++--- core/workspace_svg.js | 15 +++++++-------- 8 files changed, 41 insertions(+), 47 deletions(-) diff --git a/core/block_drag_surface.js b/core/block_drag_surface.js index 5a3948419..d87809519 100644 --- a/core/block_drag_surface.js +++ b/core/block_drag_surface.js @@ -20,10 +20,10 @@ /** * @fileoverview A class that manages a surface for dragging blocks. When a - * block drag is started, we move the block (and children) to a separate dom + * block drag is started, we move the block (and children) to a separate DOM * element that we move around using translate3d. At the end of the drag, the - * blocks are put back in into the svg they came from. This helps performance by - * avoiding repainting the entire svg on every mouse move while dragging blocks. + * blocks are put back in into the SVG they came from. This helps performance by + * avoiding repainting the entire SVG on every mouse move while dragging blocks. * @author picklesrus */ diff --git a/core/block_render_svg.js b/core/block_render_svg.js index e51e5bf08..2166860b0 100644 --- a/core/block_render_svg.js +++ b/core/block_render_svg.js @@ -326,9 +326,8 @@ Blockly.BlockSvg.prototype.render = function(opt_bubble) { * @return {number} X-coordinate of the end of the field row (plus a gap). * @private */ -Blockly.BlockSvg.prototype.renderFields_ = - function(fieldList, cursorX, cursorY) { - /* eslint-disable indent */ +Blockly.BlockSvg.prototype.renderFields_ = function(fieldList, + cursorX, cursorY) { cursorY += Blockly.BlockSvg.INLINE_PADDING_Y; if (this.RTL) { cursorX = -cursorX; @@ -356,7 +355,7 @@ Blockly.BlockSvg.prototype.renderFields_ = } } return this.RTL ? -cursorX : cursorX; -}; /* eslint-enable indent */ +}; /** * Computes the height and widths for each row and field. @@ -614,9 +613,8 @@ Blockly.BlockSvg.prototype.renderMoveConnections_ = function() { * @param {number} rightEdge Minimum width of block. * @private */ -Blockly.BlockSvg.prototype.renderDrawTop_ = - function(steps, highlightSteps, rightEdge) { - /* eslint-disable indent */ +Blockly.BlockSvg.prototype.renderDrawTop_ = function(steps, + highlightSteps, rightEdge) { // Position the cursor at the top-left starting point. if (this.squareTopLeftCorner_) { steps.push('m 0,0'); @@ -651,7 +649,7 @@ Blockly.BlockSvg.prototype.renderDrawTop_ = steps.push('H', rightEdge); highlightSteps.push('H', rightEdge - 0.5); this.width = rightEdge; -}; /* eslint-enable indent */ +}; /** * Render the right edge of the block. @@ -916,9 +914,8 @@ Blockly.BlockSvg.prototype.renderDrawRight_ = function(steps, highlightSteps, * @param {number} cursorY Height of block. * @private */ -Blockly.BlockSvg.prototype.renderDrawBottom_ = - function(steps, highlightSteps, cursorY) { - /* eslint-disable indent */ +Blockly.BlockSvg.prototype.renderDrawBottom_ = function(steps, + highlightSteps, cursorY) { this.height += cursorY + 1; // Add one for the shadow. if (this.nextConnection) { steps.push('H', (Blockly.BlockSvg.NOTCH_WIDTH + (this.RTL ? 0.5 : - 0.5)) + @@ -954,7 +951,7 @@ Blockly.BlockSvg.prototype.renderDrawBottom_ = '0.5,' + (cursorY - Blockly.BlockSvg.CORNER_RADIUS)); } } -}; /* eslint-enable indent */ +}; /** * Render the left edge of the block. diff --git a/core/block_svg.js b/core/block_svg.js index f6cdadc0d..f21c1ecd1 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -252,7 +252,7 @@ Blockly.BlockSvg.prototype.setParent = function(newParent) { // Move this block up the DOM. Keep track of x/y translations. var xy = this.getRelativeToSurfaceXY(); this.workspace.getCanvas().appendChild(svgRoot); - svgRoot.setAttribute('transform', 'translate(' + xy.x + ',' + xy.y + ')'); + svgRoot.setAttribute('transform', 'translate' + xy); } Blockly.Field.startCache(); @@ -383,7 +383,7 @@ Blockly.BlockSvg.prototype.moveDuringDrag = function(newLoc) { if (this.useDragSurface_) { this.workspace.blockDragSurface_.translateSurface(newLoc.x, newLoc.y); } else { - this.svgGroup_.translate_ = 'translate(' + newLoc.x + ',' + newLoc.y + ')'; + this.svgGroup_.translate_ = 'translate' + newLoc; this.svgGroup_.setAttribute('transform', this.svgGroup_.translate_ + this.svgGroup_.skew_); } @@ -1277,8 +1277,8 @@ Blockly.BlockSvg.prototype.setColour = function(colour) { /** * Move this block to the front of the visible workspace. - * tags do not respect z-index so svg renders them in the - * order that they are in the dom. By placing this block first within the + * tags do not respect z-index so SVG renders them in the + * order that they are in the DOM. By placing this block first within the * block group's , it will render on top of any other blocks. * @package */ @@ -1294,12 +1294,11 @@ Blockly.BlockSvg.prototype.bringToFront = function() { /** * Set whether this block can chain onto the bottom of another block. * @param {boolean} newBoolean True if there can be a previous statement. - * @param {string|Array.|null|undefined} opt_check Statement type or + * @param {(string|Array.|null)=} opt_check Statement type or * list of statement types. Null/undefined if any type could be connected. */ -Blockly.BlockSvg.prototype.setPreviousStatement = - function(newBoolean, opt_check) { - /* eslint-disable indent */ +Blockly.BlockSvg.prototype.setPreviousStatement = function(newBoolean, + opt_check) { Blockly.BlockSvg.superClass_.setPreviousStatement.call(this, newBoolean, opt_check); @@ -1307,12 +1306,12 @@ Blockly.BlockSvg.prototype.setPreviousStatement = this.render(); this.bumpNeighbours_(); } -}; /* eslint-enable indent */ +}; /** * Set whether another block can chain onto the bottom of this block. * @param {boolean} newBoolean True if there can be a next statement. - * @param {string|Array.|null|undefined} opt_check Statement type or + * @param {(string|Array.|null)=} opt_check Statement type or * list of statement types. Null/undefined if any type could be connected. */ Blockly.BlockSvg.prototype.setNextStatement = function(newBoolean, opt_check) { @@ -1328,7 +1327,7 @@ Blockly.BlockSvg.prototype.setNextStatement = function(newBoolean, opt_check) { /** * Set whether this block returns a value. * @param {boolean} newBoolean True if there is an output. - * @param {string|Array.|null|undefined} opt_check Returned type or list + * @param {(string|Array.|null)=} opt_check Returned type or list * of returned types. Null or undefined if any type could be returned * (e.g. variable get). */ diff --git a/core/flyout_button.js b/core/flyout_button.js index 0a3a83414..d25052468 100644 --- a/core/flyout_button.js +++ b/core/flyout_button.js @@ -145,13 +145,13 @@ Blockly.FlyoutButton.prototype.createDom = function() { // Background rectangle. var rect = Blockly.utils.createSvgElement('rect', {'class': this.isLabel_ ? - 'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground', - 'rx': 4, 'ry': 4}, + 'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground', + 'rx': 4, 'ry': 4}, this.svgGroup_); var svgText = Blockly.utils.createSvgElement('text', {'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', - 'x': 0, 'y': 0, 'text-anchor': 'middle'}, + 'x': 0, 'y': 0, 'text-anchor': 'middle'}, this.svgGroup_); svgText.textContent = this.text_; @@ -185,12 +185,11 @@ Blockly.FlyoutButton.prototype.show = function() { }; /** - * Update svg attributes to match internal state. + * Update SVG attributes to match internal state. * @private */ Blockly.FlyoutButton.prototype.updateTransform_ = function() { - this.svgGroup_.setAttribute('transform', - 'translate(' + this.position_.x + ',' + this.position_.y + ')'); + this.svgGroup_.setAttribute('transform', 'translate' + this.position_); }; /** diff --git a/core/inject.js b/core/inject.js index ff196202e..2b1c2ee3d 100644 --- a/core/inject.js +++ b/core/inject.js @@ -54,7 +54,7 @@ Blockly.inject = function(container, opt_options) { throw 'Error: container is not in current document.'; } var options = new Blockly.Options(opt_options || {}); - var subContainer = goog.dom.createDom('div', 'injectionDiv'); + var subContainer = goog.dom.createDom(goog.dom.TagName.DIV, 'injectionDiv'); container.appendChild(subContainer); var svg = Blockly.createDom_(subContainer, options); diff --git a/core/scrollbar.js b/core/scrollbar.js index 8498b2419..3849a6385 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -202,7 +202,7 @@ Blockly.Scrollbar = function(workspace, horizontal, opt_pair, opt_class) { this.createDom_(opt_class); /** - * The upper left corner of the scrollbar's svg group in CSS pixels relative + * The upper left corner of the scrollbar's SVG group in CSS pixels relative * to the scrollbar's origin. This is usually relative to the injection div * origin. * @type {goog.math.Coordinate} @@ -395,7 +395,7 @@ Blockly.ScrollbarPair.prototype.setContainerVisible = function(visible) { }; /** - * Set the position of the scrollbar's svg group in CSS pixels relative to the + * Set the position of the scrollbar's SVG group in CSS pixels relative to the * scrollbar's origin. This sets the scrollbar's location within the workspace. * @param {number} x The new x coordinate. * @param {number} y The new y coordinate. @@ -668,7 +668,7 @@ Blockly.Scrollbar.prototype.setVisible = function(visible) { * Update visibility of scrollbar based on whether it thinks it should * be visible and whether its containing workspace is visible. * We cannot rely on the containing workspace being hidden to hide us - * because it is not necessarily our parent in the dom. + * because it is not necessarily our parent in the DOM. */ Blockly.Scrollbar.prototype.updateDisplay_ = function() { var show = true; diff --git a/core/workspace_drag_surface_svg.js b/core/workspace_drag_surface_svg.js index 6309a05a5..e24886acc 100644 --- a/core/workspace_drag_surface_svg.js +++ b/core/workspace_drag_surface_svg.js @@ -168,9 +168,9 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) { * @param {!Element} blockCanvas The block canvas element from the workspace. * @param {!Element} bubbleCanvas The element that contains the bubbles. * @param {?Element} previousSibling The element to insert the block canvas & - bubble canvas after when it goes back in the dom at the end of a drag. - * @param {number} width The width of the workspace svg element. - * @param {number} height The height of the workspace svg element. + bubble canvas after when it goes back in the DOM at the end of a drag. + * @param {number} width The width of the workspace SVG element. + * @param {number} height The height of the workspace SVG element. * @param {number} scale The scale of the workspace being dragged. * @package */ diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 754d2bf0f..d994e94f7 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -516,7 +516,7 @@ Blockly.WorkspaceSvg.prototype.addZoomControls_ = function(bottom) { /** * Add a flyout element in an element with the given tag name. * @param {string} tagName What type of tag the flyout belongs in. - * @return {!Element} The element containing the flyout dom. + * @return {!Element} The element containing the flyout DOM. * @private */ Blockly.WorkspaceSvg.prototype.addFlyout_ = function(tagName) { @@ -623,8 +623,8 @@ Blockly.WorkspaceSvg.prototype.resize = function() { * scroll position. * @package */ -Blockly.WorkspaceSvg.prototype.updateScreenCalculationsIfScrolled - = function() { +Blockly.WorkspaceSvg.prototype.updateScreenCalculationsIfScrolled = + function() { /* eslint-disable indent */ var currScroll = goog.dom.getDocumentScroll(); if (!goog.math.Coordinate.equals(this.lastRecordedPageScroll_, @@ -691,7 +691,7 @@ Blockly.WorkspaceSvg.prototype.translate = function(x, y) { /** * Called at the end of a workspace drag to take the contents - * out of the drag surface and put them back into the workspace svg. + * out of the drag surface and put them back into the workspace SVG. * Does nothing if the workspace drag surface is not enabled. * @package */ @@ -705,8 +705,7 @@ Blockly.WorkspaceSvg.prototype.resetDragSurface = function() { var trans = this.workspaceDragSurface_.getSurfaceTranslation(); this.workspaceDragSurface_.clearAndHide(this.svgGroup_); - var translation = 'translate(' + trans.x + ',' + trans.y + ') ' + - 'scale(' + this.scale + ')'; + var translation = 'translate' + trans + ' scale(' + this.scale + ')'; this.svgBlockCanvas_.setAttribute('transform', translation); this.svgBubbleCanvas_.setAttribute('transform', translation); }; @@ -737,8 +736,8 @@ Blockly.WorkspaceSvg.prototype.setupDragSurface = function() { // Figure out where we want to put the canvas back. The order // in the is important because things are layered. var previousElement = this.svgBlockCanvas_.previousSibling; - var width = this.getParentSvg().getAttribute("width"); - var height = this.getParentSvg().getAttribute("height"); + var width = this.getParentSvg().getAttribute('width'); + var height = this.getParentSvg().getAttribute('height'); var coord = Blockly.utils.getRelativeXY(this.svgBlockCanvas_); this.workspaceDragSurface_.setContentsAndShow(this.svgBlockCanvas_, this.svgBubbleCanvas_, previousElement, width, height, this.scale);