Merge pull request #359 from rachel-fenichel/cleanup/lint

Lint
This commit is contained in:
rachel-fenichel 2016-05-10 14:44:16 -07:00
commit fe09cc9eb2
14 changed files with 139 additions and 74 deletions

View file

@ -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.<!Blockly.Block>} */
/**
* @type {!Array.<!Blockly.Block>}
* @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 = {

View file

@ -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.

View file

@ -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 {

View file

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

View file

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

View file

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

View file

@ -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() {

View file

@ -315,6 +315,6 @@ Blockly.FieldAngle.angleValidator = function(text) {
n -= 360;
}
n = String(n);
}
}
return n;
};

View file

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

View file

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

View file

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

View file

@ -43,15 +43,30 @@ Blockly.Workspace = function(opt_options) {
this.options = opt_options || {};
/** @type {boolean} */
this.RTL = !!this.options.RTL;
/** @type {!Array.<!Blockly.Block>} */
/**
* @type {!Array.<!Blockly.Block>}
* @private
*/
this.topBlocks_ = [];
/** @type {!Array.<!Function>} */
/**
* @type {!Array.<!Function>}
* @private
*/
this.listeners_ = [];
/** @type {!Array.<!Blockly.Events.Abstract>} */
/**
* @type {!Array.<!Blockly.Events.Abstract>}
* @private
*/
this.undoStack_ = [];
/** @type {!Array.<!Blockly.Events.Abstract>} */
/**
* @type {!Array.<!Blockly.Events.Abstract>}
* @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.

View file

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

View file

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