mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
lint
This commit is contained in:
parent
f468b6a6cb
commit
640b38f38e
23 changed files with 191 additions and 128 deletions
|
@ -72,25 +72,54 @@ 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} */
|
||||
|
@ -193,13 +222,13 @@ Blockly.Block.prototype.dispose = function(healStack) {
|
|||
}
|
||||
// Then dispose of myself.
|
||||
// Dispose of all inputs and their fields.
|
||||
for (var i = 0, input; input = this.inputList[i]; i++) {
|
||||
for (var j = 0, input; input = this.inputList[j]; j++) {
|
||||
input.dispose();
|
||||
}
|
||||
this.inputList.length = 0;
|
||||
// Dispose of any remaining connections (next/previous/output).
|
||||
var connections = this.getConnections_(true);
|
||||
for (var i = 0; i < connections.length; i++) {
|
||||
for (i = 0; i < connections.length; i++) {
|
||||
var connection = connections[i];
|
||||
if (connection.isConnected()) {
|
||||
connection.disconnect();
|
||||
|
@ -557,7 +586,7 @@ Blockly.Block.prototype.setConnectionsHidden = function(hidden) {
|
|||
for (var i = 0, connection; connection = myConnections[i]; i++) {
|
||||
connection.setHidden(hidden);
|
||||
if (connection.isSuperior()) {
|
||||
var child = connection.targetBlock();
|
||||
child = connection.targetBlock();
|
||||
if (child) {
|
||||
child.setConnectionsHidden(hidden);
|
||||
}
|
||||
|
@ -814,7 +843,7 @@ Blockly.Block.prototype.getInputsInline = function() {
|
|||
return false;
|
||||
}
|
||||
}
|
||||
for (var i = 1; i < this.inputList.length; i++) {
|
||||
for (i = 1; i < this.inputList.length; i++) {
|
||||
if (this.inputList[i - 1].type == Blockly.INPUT_VALUE &&
|
||||
this.inputList[i].type == Blockly.DUMMY_INPUT) {
|
||||
// Dummy input after a value input. Inline them.
|
||||
|
@ -1020,11 +1049,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 = {
|
||||
|
@ -1034,7 +1063,7 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
|
|||
};
|
||||
// Populate block with inputs and fields.
|
||||
var fieldStack = [];
|
||||
for (var i = 0; i < elements.length; i++) {
|
||||
for (i = 0; i < elements.length; i++) {
|
||||
var element = elements[i];
|
||||
if (typeof element == 'string') {
|
||||
fieldStack.push([element, undefined]);
|
||||
|
|
|
@ -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;
|
||||
|
@ -104,7 +119,7 @@ Blockly.BlockSvg.prototype.initSvg = function() {
|
|||
input.init();
|
||||
}
|
||||
var icons = this.getIcons();
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
for (i = 0; i < icons.length; i++) {
|
||||
icons[i].createIcon();
|
||||
}
|
||||
this.updateColour();
|
||||
|
@ -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.
|
||||
|
@ -429,7 +447,7 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
|
|||
var COLLAPSED_INPUT_NAME = '_TEMP_COLLAPSED_INPUT';
|
||||
if (collapsed) {
|
||||
var icons = this.getIcons();
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
for (i = 0; i < icons.length; i++) {
|
||||
icons[i].setVisible(false);
|
||||
}
|
||||
var text = this.toString(Blockly.COLLAPSE_CHARS);
|
||||
|
@ -446,7 +464,7 @@ Blockly.BlockSvg.prototype.setCollapsed = function(collapsed) {
|
|||
renderList[0] = this;
|
||||
}
|
||||
if (this.rendered) {
|
||||
for (var i = 0, block; block = renderList[i]; i++) {
|
||||
for (var j = 0, block; block = renderList[j]; j++) {
|
||||
block.render();
|
||||
}
|
||||
// Don't bump neighbours.
|
||||
|
@ -479,7 +497,7 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
|
|||
}
|
||||
}
|
||||
}
|
||||
var i = list.indexOf(start);
|
||||
i = list.indexOf(start);
|
||||
if (i == -1) {
|
||||
// No start location, start at the beginning or end.
|
||||
i = forward ? -1 : list.length;
|
||||
|
@ -774,12 +792,12 @@ Blockly.BlockSvg.prototype.moveConnections_ = function(dx, dy) {
|
|||
myConnections[i].moveBy(dx, dy);
|
||||
}
|
||||
var icons = this.getIcons();
|
||||
for (var i = 0; i < icons.length; i++) {
|
||||
for (i = 0; i < icons.length; i++) {
|
||||
icons[i].computeIconLocation();
|
||||
}
|
||||
|
||||
// Recurse through all blocks attached under this one.
|
||||
for (var i = 0; i < this.childBlocks_.length; i++) {
|
||||
for (i = 0; i < this.childBlocks_.length; i++) {
|
||||
this.childBlocks_[i].moveConnections_(dx, dy);
|
||||
}
|
||||
};
|
||||
|
@ -844,7 +862,7 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) {
|
|||
if (Blockly.dragMode_ == Blockly.DRAG_FREE) {
|
||||
// Unrestricted dragging.
|
||||
var dxy = goog.math.Coordinate.difference(oldXY, this.dragStartXY_);
|
||||
var group = this.getSvgRoot();
|
||||
group = this.getSvgRoot();
|
||||
group.translate_ = 'translate(' + newXY.x + ',' + newXY.y + ')';
|
||||
group.setAttribute('transform', group.translate_ + group.skew_);
|
||||
// Drag all the nested bubbles.
|
||||
|
@ -860,7 +878,7 @@ Blockly.BlockSvg.prototype.onMouseMove_ = function(e) {
|
|||
var closestConnection = null;
|
||||
var localConnection = null;
|
||||
var radiusConnection = Blockly.SNAP_RADIUS;
|
||||
for (var i = 0; i < myConnections.length; i++) {
|
||||
for (i = 0; i < myConnections.length; i++) {
|
||||
var myConnection = myConnections[i];
|
||||
var neighbour = myConnection.closest(radiusConnection, dxy);
|
||||
if (neighbour.connection) {
|
||||
|
|
|
@ -462,10 +462,10 @@ Blockly.getMainWorkspaceMetrics_ = function() {
|
|||
var bottomEdge = Math.max(contentY + contentHeight + viewHeight / 2,
|
||||
contentY + viewHeight);
|
||||
} else {
|
||||
var leftEdge = blockBox.x;
|
||||
var rightEdge = leftEdge + blockBox.width;
|
||||
var topEdge = blockBox.y;
|
||||
var bottomEdge = topEdge + blockBox.height;
|
||||
leftEdge = blockBox.x;
|
||||
rightEdge = leftEdge + blockBox.width;
|
||||
topEdge = blockBox.y;
|
||||
bottomEdge = topEdge + blockBox.height;
|
||||
}
|
||||
var absoluteLeft = 0;
|
||||
if (!this.RTL && this.toolbox_) {
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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++;
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -161,7 +161,7 @@ Blockly.Events.filter = function(queueIn, forward) {
|
|||
}
|
||||
}
|
||||
// Remove null events.
|
||||
for (var i = queue.length - 1; i >= 0; i--) {
|
||||
for (i = queue.length - 1; i >= 0; i--) {
|
||||
if (queue[i].isNull()) {
|
||||
queue.splice(i, 1);
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ Blockly.Events.filter = function(queueIn, forward) {
|
|||
}
|
||||
// Move mutation events to the top of the queue.
|
||||
// Intentionally skip first event.
|
||||
for (var i = 1, event; event = queue[i]; i++) {
|
||||
for (var k = 1, event; event = queue[k]; k++) {
|
||||
if (event.type == Blockly.Events.CHANGE &&
|
||||
event.element == 'mutation') {
|
||||
queue.unshift(queue.splice(i, 1)[0]);
|
||||
|
@ -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;
|
||||
|
|
|
@ -254,11 +254,11 @@ Blockly.Field.prototype.render_ = function() {
|
|||
var width = Blockly.Field.cacheWidths_[key];
|
||||
} else {
|
||||
try {
|
||||
var width = this.textElement_.getComputedTextLength();
|
||||
width = this.textElement_.getComputedTextLength();
|
||||
} catch (e) {
|
||||
// MSIE 11 is known to throw "Unexpected call to method or property
|
||||
// access." if Blockly is hidden.
|
||||
var width = this.textElement_.textContent.length * 8;
|
||||
width = this.textElement_.textContent.length * 8;
|
||||
}
|
||||
if (Blockly.Field.cacheWidths_) {
|
||||
Blockly.Field.cacheWidths_[key] = width;
|
||||
|
@ -269,7 +269,7 @@ Blockly.Field.prototype.render_ = function() {
|
|||
width + Blockly.BlockSvg.SEP_SPACE_X);
|
||||
}
|
||||
} else {
|
||||
var width = 0;
|
||||
width = 0;
|
||||
}
|
||||
this.size_.width = width;
|
||||
};
|
||||
|
@ -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() {
|
||||
|
|
|
@ -66,7 +66,7 @@ Blockly.FieldAngle.prototype.setValidator = function(handler) {
|
|||
if (v1 === undefined) {
|
||||
v1 = value;
|
||||
}
|
||||
var v2 = Blockly.FieldAngle.angleValidator.call(this, v1);
|
||||
v2 = Blockly.FieldAngle.angleValidator.call(this, v1);
|
||||
if (v2 === undefined) {
|
||||
v2 = v1;
|
||||
}
|
||||
|
@ -315,6 +315,6 @@ Blockly.FieldAngle.angleValidator = function(text) {
|
|||
n -= 360;
|
||||
}
|
||||
n = String(n);
|
||||
}
|
||||
}
|
||||
return n;
|
||||
};
|
||||
|
|
|
@ -64,7 +64,7 @@ Blockly.FieldVariable.prototype.setValidator = function(handler) {
|
|||
if (v1 === undefined) {
|
||||
v1 = value;
|
||||
}
|
||||
var v2 = Blockly.FieldVariable.dropdownChange.call(this, v1);
|
||||
v2 = Blockly.FieldVariable.dropdownChange.call(this, v1);
|
||||
if (v2 === undefined) {
|
||||
v2 = v1;
|
||||
}
|
||||
|
@ -128,7 +128,7 @@ Blockly.FieldVariable.dropdownCreate = function() {
|
|||
var variableList =
|
||||
Blockly.Variables.allVariables(this.sourceBlock_.workspace);
|
||||
} else {
|
||||
var variableList = [];
|
||||
variableList = [];
|
||||
}
|
||||
// Ensure that the currently selected variable is an option.
|
||||
var name = this.getText();
|
||||
|
|
|
@ -216,18 +216,18 @@ Blockly.createMainWorkspace_ = function(svg, options) {
|
|||
block.moveBy(0, overflow);
|
||||
}
|
||||
// Bump any block that's below the bottom back inside.
|
||||
var overflow = edgeTop + metrics.viewHeight - MARGIN - blockXY.y;
|
||||
overflow = edgeTop + metrics.viewHeight - MARGIN - blockXY.y;
|
||||
if (overflow < 0) {
|
||||
block.moveBy(0, overflow);
|
||||
}
|
||||
// Bump any block that's off the left back inside.
|
||||
var overflow = MARGIN + edgeLeft -
|
||||
overflow = MARGIN + edgeLeft -
|
||||
blockXY.x - (options.RTL ? 0 : blockHW.width);
|
||||
if (overflow > 0) {
|
||||
block.moveBy(overflow, 0);
|
||||
}
|
||||
// Bump any block that's off the right back inside.
|
||||
var overflow = edgeLeft + metrics.viewWidth - MARGIN -
|
||||
overflow = edgeLeft + metrics.viewWidth - MARGIN -
|
||||
blockXY.x + (options.RTL ? blockHW.width : 0);
|
||||
if (overflow < 0) {
|
||||
block.moveBy(overflow, 0);
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -115,7 +115,7 @@ Blockly.Mutator.prototype.createEditor_ = function() {
|
|||
quarkXml.appendChild(goog.dom.createDom('block', {'type': quarkName}));
|
||||
}
|
||||
} else {
|
||||
var quarkXml = null;
|
||||
quarkXml = null;
|
||||
}
|
||||
var workspaceOptions = {
|
||||
languageTree: quarkXml,
|
||||
|
@ -223,8 +223,8 @@ Blockly.Mutator.prototype.setVisible = function(visible) {
|
|||
var margin = this.workspace_.flyout_.CORNER_RADIUS * 2;
|
||||
var x = this.workspace_.flyout_.width_ + margin;
|
||||
} else {
|
||||
var margin = 16;
|
||||
var x = margin;
|
||||
margin = 16;
|
||||
x = margin;
|
||||
}
|
||||
if (this.block_.RTL) {
|
||||
x = -x;
|
||||
|
@ -283,7 +283,7 @@ Blockly.Mutator.prototype.workspaceChanged_ = function() {
|
|||
// When the mutator's workspace changes, update the source block.
|
||||
if (this.rootBlock_.workspace == this.workspace_) {
|
||||
Blockly.Events.setGroup(true);
|
||||
var block = this.block_;
|
||||
block = this.block_;
|
||||
var oldMutationDom = block.mutationToDom();
|
||||
var oldMutation = oldMutationDom && Blockly.Xml.domToText(oldMutationDom);
|
||||
// Switch off rendering while the source block is rebuilt.
|
||||
|
|
|
@ -45,26 +45,26 @@ Blockly.Options = function(options) {
|
|||
var hasDisable = false;
|
||||
var hasSounds = false;
|
||||
} else {
|
||||
var languageTree = Blockly.Options.parseToolboxTree(options['toolbox']);
|
||||
var hasCategories = Boolean(languageTree &&
|
||||
languageTree = Blockly.Options.parseToolboxTree(options['toolbox']);
|
||||
hasCategories = Boolean(languageTree &&
|
||||
languageTree.getElementsByTagName('category').length);
|
||||
var hasTrashcan = options['trashcan'];
|
||||
hasTrashcan = options['trashcan'];
|
||||
if (hasTrashcan === undefined) {
|
||||
hasTrashcan = hasCategories;
|
||||
}
|
||||
var hasCollapse = options['collapse'];
|
||||
hasCollapse = options['collapse'];
|
||||
if (hasCollapse === undefined) {
|
||||
hasCollapse = hasCategories;
|
||||
}
|
||||
var hasComments = options['comments'];
|
||||
hasComments = options['comments'];
|
||||
if (hasComments === undefined) {
|
||||
hasComments = hasCategories;
|
||||
}
|
||||
var hasDisable = options['disable'];
|
||||
hasDisable = options['disable'];
|
||||
if (hasDisable === undefined) {
|
||||
hasDisable = hasCategories;
|
||||
}
|
||||
var hasSounds = options['sounds'];
|
||||
hasSounds = options['sounds'];
|
||||
if (hasSounds === undefined) {
|
||||
hasSounds = true;
|
||||
}
|
||||
|
|
|
@ -285,7 +285,7 @@ Blockly.Toolbox.prototype.addColour_ = function(opt_tree) {
|
|||
if (this.hasColours_) {
|
||||
var border = '8px solid ' + (child.hexColour || '#ddd');
|
||||
} else {
|
||||
var border = 'none';
|
||||
border = 'none';
|
||||
}
|
||||
if (this.workspace_.RTL) {
|
||||
element.style.borderRight = border;
|
||||
|
@ -321,7 +321,7 @@ Blockly.Toolbox.prototype.getClientRect = function() {
|
|||
return new goog.math.Rect(toolboxRect.left, -BIG_NUM, width, BIG_NUM * 2);
|
||||
}
|
||||
// LTR
|
||||
var width = BIG_NUM + toolboxRect.width + toolboxRect.left;
|
||||
width = BIG_NUM + toolboxRect.width + toolboxRect.left;
|
||||
return new goog.math.Rect(-BIG_NUM, -BIG_NUM, width, BIG_NUM * 2);
|
||||
};
|
||||
|
||||
|
|
|
@ -317,7 +317,7 @@ Blockly.Tooltip.wrap_ = function(text, limit) {
|
|||
// Seed the list with evenly spaced linebreaks.
|
||||
var steps = words.length / lineCount;
|
||||
var insertedBreaks = 1;
|
||||
for (var i = 0; i < words.length - 1; i++) {
|
||||
for (i = 0; i < words.length - 1; i++) {
|
||||
if (insertedBreaks < (i + 1.5) / steps) {
|
||||
insertedBreaks++;
|
||||
wordBreaks[i] = true;
|
||||
|
@ -358,7 +358,7 @@ Blockly.Tooltip.wrapScore_ = function(words, wordBreaks, limit) {
|
|||
var maxLength = Math.max.apply(Math, lineLengths);
|
||||
|
||||
var score = 0;
|
||||
for (var i = 0; i < lineLengths.length; i++) {
|
||||
for (i = 0; i < lineLengths.length; i++) {
|
||||
// Optimize for width.
|
||||
// -2 points per char over limit (scaled to the power of 1.5).
|
||||
score -= Math.pow(Math.abs(limit - lineLengths[i]), 1.5) * 2;
|
||||
|
|
|
@ -167,7 +167,7 @@ Blockly.Trashcan.prototype.createDom = function() {
|
|||
body.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||
this.workspace_.options.pathToMedia + Blockly.SPRITE.url);
|
||||
|
||||
var clip = Blockly.createSvgElement('clipPath',
|
||||
clip = Blockly.createSvgElement('clipPath',
|
||||
{'id': 'blocklyTrashLidClipPath' + rnd},
|
||||
this.svgGroup_);
|
||||
Blockly.createSvgElement('rect',
|
||||
|
|
|
@ -104,7 +104,7 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) {
|
|||
func.call(thisObject, e);
|
||||
};
|
||||
} else {
|
||||
var wrapFunc = func;
|
||||
wrapFunc = func;
|
||||
}
|
||||
node.addEventListener(name, wrapFunc, false);
|
||||
var bindData = [[node, name, wrapFunc]];
|
||||
|
@ -295,11 +295,11 @@ Blockly.createSvgElement = function(name, attrs, parent, opt_workspace) {
|
|||
* @param {boolean} selectable Whether elements on the page can be selected.
|
||||
*/
|
||||
Blockly.setPageSelectable = function(selectable) {
|
||||
if (selectable) {
|
||||
Blockly.removeClass_(document.body, 'blocklyNonSelectable');
|
||||
} else {
|
||||
Blockly.addClass_(document.body, 'blocklyNonSelectable');
|
||||
}
|
||||
if (selectable) {
|
||||
Blockly.removeClass_(document.body, 'blocklyNonSelectable');
|
||||
} else {
|
||||
Blockly.addClass_(document.body, 'blocklyNonSelectable');
|
||||
}
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -374,8 +374,8 @@ Blockly.commonWordPrefix = function(array, opt_shortest) {
|
|||
wordPrefix = len + 1;
|
||||
}
|
||||
}
|
||||
for (var i = 1; i < array.length; i++) {
|
||||
var letter = array[i][len];
|
||||
for (i = 1; i < array.length; i++) {
|
||||
letter = array[i][len];
|
||||
if (letter && letter != ' ') {
|
||||
return wordPrefix;
|
||||
}
|
||||
|
@ -409,8 +409,8 @@ Blockly.commonWordSuffix = function(array, opt_shortest) {
|
|||
wordPrefix = len + 1;
|
||||
}
|
||||
}
|
||||
for (var i = 1; i < array.length; i++) {
|
||||
var letter = array[i].charAt(array[i].length - len - 1);
|
||||
for (i = 1; i < array.length; i++) {
|
||||
letter = array[i].charAt(array[i].length - len - 1);
|
||||
if (letter && letter != ' ') {
|
||||
return wordPrefix;
|
||||
}
|
||||
|
@ -478,7 +478,7 @@ Blockly.tokenizeInterpolation = function(message) {
|
|||
}
|
||||
}
|
||||
}
|
||||
var text = buffer.join('');
|
||||
text = buffer.join('');
|
||||
if (text) {
|
||||
tokens.push(text);
|
||||
}
|
||||
|
@ -488,7 +488,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;
|
||||
|
|
|
@ -123,12 +123,12 @@ Blockly.Variables.flyoutCategory = function(workspace) {
|
|||
// <block type="variables_get" gap="24">
|
||||
// <field name="VAR">item</field>
|
||||
// </block>
|
||||
var block = goog.dom.createDom('block');
|
||||
block = goog.dom.createDom('block');
|
||||
block.setAttribute('type', 'variables_get');
|
||||
if (Blockly.Blocks['variables_set']) {
|
||||
block.setAttribute('gap', 24);
|
||||
}
|
||||
var field = goog.dom.createDom('field', null, variableList[i]);
|
||||
field = goog.dom.createDom('field', null, variableList[i]);
|
||||
field.setAttribute('name', 'VAR');
|
||||
block.appendChild(field);
|
||||
xmlList.push(block);
|
||||
|
|
|
@ -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.
|
||||
|
@ -220,7 +235,7 @@ Blockly.Workspace.prototype.undo = function(redo) {
|
|||
}
|
||||
events = Blockly.Events.filter(events, redo);
|
||||
Blockly.Events.recordUndo = false;
|
||||
for (var i = 0, event; event = events[i]; i++) {
|
||||
for (i = 0; event = events[i]; i++) {
|
||||
event.run(redo);
|
||||
}
|
||||
Blockly.Events.recordUndo = true;
|
||||
|
|
|
@ -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;});
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -486,7 +486,7 @@ Blockly.WorkspaceSvg.prototype.paste = function(xmlBlock) {
|
|||
if (!collide) {
|
||||
// Check for blocks in snap range to any of its connections.
|
||||
var connections = block.getConnections_(false);
|
||||
for (var i = 0, connection; connection = connections[i]; i++) {
|
||||
for (var j = 0, connection; connection = connections[j]; j++) {
|
||||
var neighbour = connection.closest(Blockly.SNAP_RADIUS,
|
||||
new goog.math.Coordinate(blockX, blockY));
|
||||
if (neighbour.connection) {
|
||||
|
@ -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)) {
|
||||
|
@ -809,7 +808,7 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) {
|
|||
}
|
||||
}
|
||||
}
|
||||
for (var i = 0; i < topBlocks.length; i++) {
|
||||
for (i = 0; i < topBlocks.length; i++) {
|
||||
addDeletableBlocks(topBlocks[i]);
|
||||
}
|
||||
var deleteOption = {
|
||||
|
|
10
core/xml.js
10
core/xml.js
|
@ -109,7 +109,7 @@ Blockly.Xml.blockToDom = function(block) {
|
|||
element.appendChild(dataElement);
|
||||
}
|
||||
|
||||
for (var i = 0, input; input = block.inputList[i]; i++) {
|
||||
for (i = 0; input = block.inputList[i]; i++) {
|
||||
var container;
|
||||
var empty = true;
|
||||
if (input.type == Blockly.DUMMY_INPUT) {
|
||||
|
@ -156,11 +156,11 @@ Blockly.Xml.blockToDom = function(block) {
|
|||
|
||||
var nextBlock = block.getNextBlock();
|
||||
if (nextBlock) {
|
||||
var container = goog.dom.createDom('next', null,
|
||||
container = goog.dom.createDom('next', null,
|
||||
Blockly.Xml.blockToDom(nextBlock));
|
||||
element.appendChild(container);
|
||||
}
|
||||
var shadow = block.nextConnection && block.nextConnection.getShadowDom();
|
||||
shadow = block.nextConnection && block.nextConnection.getShadowDom();
|
||||
if (shadow && (!nextBlock || !nextBlock.isShadow())) {
|
||||
container.appendChild(Blockly.Xml.cloneShadow_(shadow));
|
||||
}
|
||||
|
@ -337,7 +337,7 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
|
|||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].initSvg();
|
||||
}
|
||||
for (var i = blocks.length - 1; i >= 0; i--) {
|
||||
for (i = blocks.length - 1; i >= 0; i--) {
|
||||
blocks[i].render(false);
|
||||
}
|
||||
// Populating the connection database may be defered until after the blocks
|
||||
|
@ -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');
|
||||
|
|
|
@ -131,7 +131,7 @@ Blockly.ZoomControls.prototype.createDom = function() {
|
|||
zoomoutSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||
workspace.options.pathToMedia + Blockly.SPRITE.url);
|
||||
|
||||
var clip = Blockly.createSvgElement('clipPath',
|
||||
clip = Blockly.createSvgElement('clipPath',
|
||||
{'id': 'blocklyZoominClipPath' + rnd},
|
||||
this.svgGroup_);
|
||||
Blockly.createSvgElement('rect',
|
||||
|
@ -147,7 +147,7 @@ Blockly.ZoomControls.prototype.createDom = function() {
|
|||
zoominSvg.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||
workspace.options.pathToMedia + Blockly.SPRITE.url);
|
||||
|
||||
var clip = Blockly.createSvgElement('clipPath',
|
||||
clip = Blockly.createSvgElement('clipPath',
|
||||
{'id': 'blocklyZoomresetClipPath' + rnd},
|
||||
this.svgGroup_);
|
||||
Blockly.createSvgElement('rect',
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue