diff --git a/core/block.js b/core/block.js index 6524e98f9..b33fe7bb4 100644 --- a/core/block.js +++ b/core/block.js @@ -72,25 +72,55 @@ Blockly.Block = function(workspace, prototypeName, opt_id) { /** @type {boolean} */ this.contextMenu = true; - /** @type {Blockly.Block} */ + /** + * @type {Blockly.Block} + * @private + */ this.parentBlock_ = null; - /** @type {!Array.} */ + + /** + * @type {!Array.} + * @private + */ this.childBlocks_ = []; - /** @type {boolean} */ + + /** + * @type {boolean} + * @private + */ this.deletable_ = true; - /** @type {boolean} */ + + /** + * @type {boolean} + * @private + */ this.movable_ = true; - /** @type {boolean} */ + + /** + * @type {boolean} + * @private + */ this.editable_ = true; - /** @type {boolean} */ + + /** + * @type {boolean} + * @private + */ this.isShadow_ = false; - /** @type {boolean} */ + + /** + * @type {boolean} + * @private + */ this.collapsed_ = false; /** @type {string|Blockly.Comment} */ this.comment = null; - /** @type {!goog.math.Coordinate} */ + /** + * @type {!goog.math.Coordinate} + * @private + */ this.xy_ = new goog.math.Coordinate(0, 0); /** @type {!Blockly.Workspace} */ @@ -1020,11 +1050,11 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) { // Add last dummy input if needed. if (elements.length && (typeof elements[elements.length - 1] == 'string' || elements[elements.length - 1]['type'].indexOf('field_') == 0)) { - var input = {type: 'input_dummy'}; + var dummyInput = {type: 'input_dummy'}; if (lastDummyAlign) { - input['align'] = lastDummyAlign; + dummyInput['align'] = lastDummyAlign; } - elements.push(input); + elements.push(dummyInput); } // Lookup of alignment constants. var alignmentLookup = { diff --git a/core/block_svg.js b/core/block_svg.js index ed867fc32..d376a9272 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -48,16 +48,31 @@ goog.require('goog.userAgent'); */ Blockly.BlockSvg = function(workspace, prototypeName, opt_id) { // Create core elements for the block. - /** @type {SVGElement} */ + /** + * @type {SVGElement} + * @private + */ this.svgGroup_ = Blockly.createSvgElement('g', {}, null); - /** @type {SVGElement} */ + + /** + * @type {SVGElement} + * @private + */ this.svgPathDark_ = Blockly.createSvgElement('path', {'class': 'blocklyPathDark', 'transform': 'translate(1,1)'}, this.svgGroup_); - /** @type {SVGElement} */ + + /** + * @type {SVGElement} + * @private + */ this.svgPath_ = Blockly.createSvgElement('path', {'class': 'blocklyPath'}, this.svgGroup_); - /** @type {SVGElement} */ + + /** + * @type {SVGElement} + * @private + */ this.svgPathLight_ = Blockly.createSvgElement('path', {'class': 'blocklyPathLight'}, this.svgGroup_); this.svgPath_.tooltip = this; @@ -365,7 +380,8 @@ Blockly.BlockSvg.prototype.snapToGrid = function() { /** * Returns a bounding box describing the dimensions of this block * and any blocks stacked below it. - * @return {!{height: number, width: number}} Object with height and width properties. + * @return {!{height: number, width: number}} Object with height and width + * properties. */ Blockly.BlockSvg.prototype.getHeightWidth = function() { var height = this.height; @@ -384,10 +400,10 @@ Blockly.BlockSvg.prototype.getHeightWidth = function() { }; /** - * Returns the coordinates of a bounding box describing the dimensions of this block - * and any blocks stacked below it. + * Returns the coordinates of a bounding box describing the dimensions of this + * block and any blocks stacked below it. * @return {!{topLeft: goog.math.Coordinate, bottomRight: goog.math.Coordinate}} - * Object with top left and bottom right coordinates of the bounding box. + * Object with top left and bottom right coordinates of the bounding box. */ Blockly.BlockSvg.prototype.getBoundingRectangle = function() { var blockXY = this.getRelativeToSurfaceXY(this); @@ -397,10 +413,12 @@ Blockly.BlockSvg.prototype.getBoundingRectangle = function() { var bottomRight; if (this.RTL) { // Width has the tab built into it already so subtract it here. - topLeft = new goog.math.Coordinate(blockXY.x - (blockBounds.width - tab), blockXY.y); + topLeft = new goog.math.Coordinate(blockXY.x - (blockBounds.width - tab), + blockXY.y); // Add the width of the tab/puzzle piece knob to the x coordinate // since X is the corner of the rectangle, not the whole puzzle piece. - bottomRight = new goog.math.Coordinate(blockXY.x + tab, blockXY.y + blockBounds.height); + bottomRight = new goog.math.Coordinate(blockXY.x + tab, + blockXY.y + blockBounds.height); } else { // Subtract the width of the tab/puzzle piece knob to the x coordinate // since X is the corner of the rectangle, not the whole puzzle piece. diff --git a/core/connection.js b/core/connection.js index 25adcf49d..1cf066e09 100644 --- a/core/connection.js +++ b/core/connection.js @@ -37,7 +37,10 @@ goog.require('goog.dom'); * @constructor */ Blockly.Connection = function(source, type) { - /** @type {!Blockly.Block} */ + /** + * @type {!Blockly.Block} + * @private + */ this.sourceBlock_ = source; /** @type {number} */ this.type = type; @@ -425,7 +428,6 @@ Blockly.Connection.prototype.connect = function(otherConnection) { } this.checkConnection_(otherConnection); // Determine which block is superior (higher in the source stack). - var parentBlock, childBlock; if (this.isSuperior()) { // Superior block. Blockly.Connection.connect_(this, otherConnection); @@ -837,8 +839,6 @@ Blockly.Connection.prototype.unhideAll = function() { Blockly.Connection.prototype.highlight = function() { var steps; if (this.type == Blockly.INPUT_VALUE || this.type == Blockly.OUTPUT_VALUE) { - var tabWidth = this.sourceBlock_.RTL ? -Blockly.BlockSvg.TAB_WIDTH : - Blockly.BlockSvg.TAB_WIDTH; steps = 'm 0,0 ' + Blockly.BlockSvg.TAB_PATH_DOWN + ' v 5'; } else { diff --git a/core/connection_db.js b/core/connection_db.js index f0b69f7f5..9d143e367 100644 --- a/core/connection_db.js +++ b/core/connection_db.js @@ -173,20 +173,7 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { pointerMid = Math.floor((pointerMin + pointerMax) / 2); } - // Walk forward and back on the y axis looking for the closest x,y point. - pointerMin = pointerMid; - pointerMax = pointerMid; var neighbours = []; - var sourceBlock = connection.getSourceBlock(); - if (db.length) { - while (pointerMin >= 0 && checkConnection_(pointerMin)) { - pointerMin--; - } - do { - pointerMax++; - } while (pointerMax < db.length && checkConnection_(pointerMax)); - } - /** * Computes if the current connection is within the allowed radius of another * connection. @@ -204,6 +191,19 @@ Blockly.ConnectionDB.prototype.getNeighbours = function(connection, maxRadius) { } return dy < maxRadius; } + + // Walk forward and back on the y axis looking for the closest x,y point. + pointerMin = pointerMid; + pointerMax = pointerMid; + if (db.length) { + while (pointerMin >= 0 && checkConnection_(pointerMin)) { + pointerMin--; + } + do { + pointerMax++; + } while (pointerMax < db.length && checkConnection_(pointerMax)); + } + return neighbours; }; @@ -260,8 +260,8 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, while (pointerMin >= 0 && this.isInYRange_(pointerMin, conn.y_, maxRadius)) { temp = this[pointerMin]; if (conn.isConnectionAllowed(temp, bestRadius)) { - bestConnection = temp; - bestRadius = temp.distanceFrom(conn); + bestConnection = temp; + bestRadius = temp.distanceFrom(conn); } pointerMin--; } @@ -271,8 +271,8 @@ Blockly.ConnectionDB.prototype.searchForClosest = function(conn, maxRadius, maxRadius)) { temp = this[pointerMax]; if (conn.isConnectionAllowed(temp, bestRadius)) { - bestConnection = temp; - bestRadius = temp.distanceFrom(conn); + bestConnection = temp; + bestRadius = temp.distanceFrom(conn); } pointerMax++; } diff --git a/core/contextmenu.js b/core/contextmenu.js index 3a1fc6e95..ebd92df17 100644 --- a/core/contextmenu.js +++ b/core/contextmenu.js @@ -58,7 +58,7 @@ Blockly.ContextMenu.show = function(e, options, rtl) { */ var menu = new goog.ui.Menu(); menu.setRightToLeft(rtl); - for (var x = 0, option; option = options[x]; x++) { + for (var i = 0, option; option = options[i]; i++) { var menuItem = new goog.ui.MenuItem(option.text); menuItem.setRightToLeft(rtl); menu.addChild(menuItem, true); diff --git a/core/events.js b/core/events.js index 3de8bc5c3..bc4299e55 100644 --- a/core/events.js +++ b/core/events.js @@ -254,6 +254,7 @@ Blockly.Events.getDescendantIds_ = function(block) { * Decode the JSON into an event. * @param {!Object} json JSON representation. * @param {!Blockly.Workspace} workspace Target workspace for event. + * @return {!Blockly.Events.Abstract} The event represented by the JSON. */ Blockly.Events.fromJson = function(json, workspace) { var event; @@ -274,7 +275,7 @@ Blockly.Events.fromJson = function(json, workspace) { event = new Blockly.Events.Ui(null); break; default: - throw 'Unknown event type.' + throw 'Unknown event type.'; } event.fromJson(json); event.workspaceId = workspace.id; diff --git a/core/field.js b/core/field.js index 30078e0f3..305ecd6d6 100644 --- a/core/field.js +++ b/core/field.js @@ -450,7 +450,7 @@ Blockly.Field.prototype.setTooltip = function(newTip) { /** * Return the absolute coordinates of the top-left corner of this field. * The origin (0,0) is the top-left corner of the page body. - * @return {{!goog.math.Coordinate}} Object with .x and .y properties. + * @return {!goog.math.Coordinate} Object with .x and .y properties. * @private */ Blockly.Field.prototype.getAbsoluteXY_ = function() { diff --git a/core/field_angle.js b/core/field_angle.js index 09cbf8ee1..b5ca196ce 100644 --- a/core/field_angle.js +++ b/core/field_angle.js @@ -315,6 +315,6 @@ Blockly.FieldAngle.angleValidator = function(text) { n -= 360; } n = String(n); - } + } return n; }; diff --git a/core/inject.js b/core/inject.js index 98935a5c9..4f84b24a3 100644 --- a/core/inject.js +++ b/core/inject.js @@ -211,26 +211,27 @@ Blockly.createMainWorkspace_ = function(svg, options) { var blockXY = block.getRelativeToSurfaceXY(); var blockHW = block.getHeightWidth(); // Bump any block that's above the top back inside. - var overflow = edgeTop + MARGIN - blockHW.height - blockXY.y; - if (overflow > 0) { - block.moveBy(0, overflow); + var overflowTop = edgeTop + MARGIN - blockHW.height - blockXY.y; + if (overflowTop > 0) { + block.moveBy(0, overflowTop); } // Bump any block that's below the bottom back inside. - var overflow = edgeTop + metrics.viewHeight - MARGIN - blockXY.y; - if (overflow < 0) { - block.moveBy(0, overflow); + var overflowBottom = + edgeTop + metrics.viewHeight - MARGIN - blockXY.y; + if (overflowBottom < 0) { + block.moveBy(0, overflowBottom); } // Bump any block that's off the left back inside. - var overflow = MARGIN + edgeLeft - + var overflowLeft = MARGIN + edgeLeft - blockXY.x - (options.RTL ? 0 : blockHW.width); - if (overflow > 0) { - block.moveBy(overflow, 0); + if (overflowLeft > 0) { + block.moveBy(overflowLeft, 0); } // Bump any block that's off the right back inside. - var overflow = edgeLeft + metrics.viewWidth - MARGIN - + var overflowRight = edgeLeft + metrics.viewWidth - MARGIN - blockXY.x + (options.RTL ? blockHW.width : 0); - if (overflow < 0) { - block.moveBy(overflow, 0); + if (overflowRight < 0) { + block.moveBy(overflowRight, 0); } } } diff --git a/core/input.js b/core/input.js index 8ca265586..27733a949 100644 --- a/core/input.js +++ b/core/input.js @@ -47,7 +47,10 @@ Blockly.Input = function(type, name, block, connection) { this.type = type; /** @type {string} */ this.name = name; - /** @type {!Blockly.Block} */ + /** + * @type {!Blockly.Block} + * @private + */ this.sourceBlock_ = block; /** @type {Blockly.Connection} */ this.connection = connection; diff --git a/core/utils.js b/core/utils.js index e65a72a6c..1a0fba1b6 100644 --- a/core/utils.js +++ b/core/utils.js @@ -475,7 +475,7 @@ Blockly.tokenizeInterpolation = function(message) { /** * Generate a unique ID. This should be globally unique. * 87 characters ^ 20 length > 128 bits (better than a UUID). - * @return {string} + * @return {string} A globally unique ID string. */ Blockly.genUid = function() { var length = 20; diff --git a/core/workspace.js b/core/workspace.js index 6f34a02e2..e67fbe564 100644 --- a/core/workspace.js +++ b/core/workspace.js @@ -43,15 +43,30 @@ Blockly.Workspace = function(opt_options) { this.options = opt_options || {}; /** @type {boolean} */ this.RTL = !!this.options.RTL; - /** @type {!Array.} */ + /** + * @type {!Array.} + * @private + */ this.topBlocks_ = []; - /** @type {!Array.} */ + /** + * @type {!Array.} + * @private + */ this.listeners_ = []; - /** @type {!Array.} */ + /** + * @type {!Array.} + * @private + */ this.undoStack_ = []; - /** @type {!Array.} */ + /** + * @type {!Array.} + * @private + */ this.redoStack_ = []; - /** @type {!Object} */ + /** + * @type {!Object} + * @private + */ this.blockDB_ = Object.create(null); }; @@ -204,14 +219,14 @@ Blockly.Workspace.prototype.remainingCapacity = function() { Blockly.Workspace.prototype.undo = function(redo) { var inputStack = redo ? this.redoStack_ : this.undoStack_; var outputStack = redo ? this.undoStack_ : this.redoStack_; - var event = inputStack.pop(); - if (!event) { + var inputEvent = inputStack.pop(); + if (!inputEvent) { return; } - var events = [event]; + var events = [inputEvent]; // Do another undo/redo if the next one is of the same group. - while (inputStack.length && event.group && - event.group == inputStack[inputStack.length - 1].group) { + while (inputStack.length && inputEvent.group && + inputEvent.group == inputStack[inputStack.length - 1].group) { events.push(inputStack.pop()); } // Push these popped events on the opposite stack. diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 562c8a5af..294dd7de0 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -413,7 +413,7 @@ Blockly.WorkspaceSvg.prototype.traceOn = function(armed) { } if (armed) { this.traceWrapper_ = Blockly.bindEvent_(this.svgBlockCanvas_, - 'blocklySelectChange', this, function() {this.traceOn_ = false}); + 'blocklySelectChange', this, function() {this.traceOn_ = false;}); } }; @@ -538,7 +538,6 @@ Blockly.WorkspaceSvg.prototype.recordDeleteAreas = function() { * @return {boolean} True if event is in a delete area. */ Blockly.WorkspaceSvg.prototype.isDeleteArea = function(e) { - var isDelete = false; var xy = new goog.math.Coordinate(e.clientX, e.clientY); if (this.deleteAreaTrash_) { if (this.deleteAreaTrash_.contains(xy)) { diff --git a/core/xml.js b/core/xml.js index 3e9e3cdc2..e2651e025 100644 --- a/core/xml.js +++ b/core/xml.js @@ -386,7 +386,6 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { // Find any enclosed blocks or shadows in this tag. var childBlockNode = null; var childShadowNode = null; - var shadowActive = false; for (var j = 0, grandchildNode; grandchildNode = xmlChild.childNodes[j]; j++) { if (grandchildNode.nodeType == 1) { @@ -400,7 +399,6 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) { // Use the shadow block if there is no child block. if (!childBlockNode && childShadowNode) { childBlockNode = childShadowNode; - shadowActive = true; } var name = xmlChild.getAttribute('name');