Resolve 106 warnings.

This commit is contained in:
Neil Fraser
2017-10-23 17:28:01 -07:00
committed by Neil Fraser
parent f992ea0f9c
commit 4262b09002
29 changed files with 154 additions and 145 deletions

View File

@@ -48,7 +48,7 @@ goog.require('goog.string');
* @param {?string} prototypeName Name of the language object containing
* type-specific functions for this block.
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new id.
* create a new ID.
* @constructor
*/
Blockly.Block = function(workspace, prototypeName, opt_id) {
@@ -261,7 +261,7 @@ Blockly.Block.prototype.dispose = function(healStack) {
/**
* Unplug this block from its superior block. If this block is a statement,
* optionally reconnect the block underneath with the block on top.
* @param {boolean} opt_healStack Disconnect child statement and reconnect
* @param {boolean=} opt_healStack Disconnect child statement and reconnect
* stack. Defaults to false.
*/
Blockly.Block.prototype.unplug = function(opt_healStack) {
@@ -619,9 +619,9 @@ Blockly.Block.prototype.setColour = function(colour) {
if (!isNaN(hue) && 0 <= hue && hue <= 360) {
this.hue_ = hue;
this.colour_ = Blockly.hueToRgb(hue);
} else if (goog.isString(colour) && colour.match(/^#[0-9a-fA-F]{6}$/)) {
} else if (goog.isString(colour) && /^#[0-9a-fA-F]{6}$/.test(colour)) {
this.colour_ = colour;
// Only store hue if colour is set as a hue
// Only store hue if colour is set as a hue.
this.hue_ = null;
} else {
throw 'Invalid colour: ' + colour;

View File

@@ -202,7 +202,7 @@ Blockly.BlockDragSurfaceSvg.prototype.getCurrentBlock = function() {
* element.
* If the block is being deleted it doesn't need to go back to the original
* surface, since it would be removed immediately during dispose.
* @param {Element} opt_newSurface Surface the dragging blocks should be moved
* @param {Element=} opt_newSurface Surface the dragging blocks should be moved
* to, or null if the blocks should be removed from this surface without
* being moved to a different surface.
*/

View File

@@ -47,7 +47,7 @@ goog.require('goog.userAgent');
* @param {?string} prototypeName Name of the language object containing
* type-specific functions for this block.
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new id.
* create a new ID.
* @extends {Blockly.Block}
* @constructor
*/
@@ -121,7 +121,7 @@ Blockly.BlockSvg.prototype.dragStartXY_ = null;
/**
* Map from IDs for warnings text to PIDs of functions to apply them.
* Used to be able to maintain multiple warnings.
* @type {Object<string, number>}
* @type {Object.<string, number>}
* @private
*/
Blockly.BlockSvg.prototype.warningTextDb_ = null;
@@ -534,7 +534,7 @@ Blockly.BlockSvg.prototype.tab = function(start, forward) {
/**
* Create an ordered list of all text fields and connected inputs.
* @return {!Array<!Blockly.FieldTextInput|!Blockly.Input>} The ordered list.
* @return {!Array.<!Blockly.FieldTextInput|!Blockly.Input>} The ordered list.
* @private
*/
Blockly.BlockSvg.prototype.createTabList_ = function() {
@@ -1160,7 +1160,7 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
}
this.warning.setText(/** @type {string} */ (text), id);
} else {
// Dispose all warnings if no id is given.
// Dispose all warnings if no ID is given.
if (this.warning && !id) {
this.warning.dispose();
changedState = true;

View File

@@ -395,14 +395,14 @@ Blockly.defineBlocksWithJsonArray = function(jsonArray) {
* Bind an event to a function call. When calling the function, verifies that
* it belongs to the touch stream that is currently being processed, and splits
* multitouch events into multiple events as needed.
* @param {!Node} node Node upon which to listen.
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
* @param {boolean} opt_noCaptureIdentifier True if triggering on this event
* @param {boolean=} opt_noCaptureIdentifier True if triggering on this event
* should not block execution of other event handlers on this touch or other
* simultaneous touches.
* @param {boolean} opt_noPreventDefault True if triggering on this event
* @param {boolean=} opt_noPreventDefault True if triggering on this event
* should prevent the default handler. False by default. If
* opt_noPreventDefault is provided, opt_noCaptureIdentifier must also be
* provided.
@@ -461,7 +461,7 @@ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func,
* simultaneous event processing.
* @deprecated in favor of bindEventWithChecks_, but preserved for external
* users.
* @param {!Node} node Node upon which to listen.
* @param {!EventTarget} node Node upon which to listen.
* @param {string} name Event name to listen to (e.g. 'mousedown').
* @param {Object} thisObject The value of 'this' in the function.
* @param {!Function} func Function to call when event is triggered.
@@ -528,7 +528,7 @@ Blockly.unbindEvent_ = function(bindData) {
* @return {boolean} True if number, false otherwise.
*/
Blockly.isNumber = function(str) {
return !!str.match(/^\s*-?\d+(\.\d+)?\s*$/);
return /^\s*-?\d+(\.\d+)?\s*$/.test(str);
};
// IE9 does not have a console. Create a stub to stop errors.

View File

@@ -32,6 +32,6 @@ goog.provide('Blockly.Blocks');
/*
* A mapping of block type names to block prototype objects.
* @type {!Object<string,Object>}
* @type {!Object.<string,Object>}
*/
Blockly.Blocks = new Object(null);

View File

@@ -482,7 +482,7 @@ Blockly.Events.Create.prototype.run = function(forward) {
block.dispose(false, false);
} else if (id == this.blockId) {
// Only complain about root-level block.
console.warn("Can't uncreate non-existant block: " + id);
console.warn("Can't uncreate non-existent block: " + id);
}
}
}
@@ -558,7 +558,7 @@ Blockly.Events.Delete.prototype.run = function(forward) {
block.dispose(false, false);
} else if (id == this.blockId) {
// Only complain about root-level block.
console.warn("Can't delete non-existant block: " + id);
console.warn("Can't delete non-existent block: " + id);
}
}
} else {
@@ -649,7 +649,7 @@ Blockly.Events.Change.prototype.run = function(forward) {
var workspace = this.getEventWorkspace_();
var block = workspace.getBlockById(this.blockId);
if (!block) {
console.warn("Can't change non-existant block: " + this.blockId);
console.warn("Can't change non-existent block: " + this.blockId);
return;
}
if (block.mutator) {
@@ -666,7 +666,7 @@ Blockly.Events.Change.prototype.run = function(forward) {
field.callValidator(value);
field.setValue(value);
} else {
console.warn("Can't set non-existant field: " + this.name);
console.warn("Can't set non-existent field: " + this.name);
}
break;
case 'comment':
@@ -818,7 +818,7 @@ Blockly.Events.Move.prototype.run = function(forward) {
var workspace = this.getEventWorkspace_();
var block = workspace.getBlockById(this.blockId);
if (!block) {
console.warn("Can't move non-existant block: " + this.blockId);
console.warn("Can't move non-existent block: " + this.blockId);
return;
}
var parentId = forward ? this.newParentId : this.oldParentId;
@@ -828,7 +828,7 @@ Blockly.Events.Move.prototype.run = function(forward) {
if (parentId) {
parentBlock = workspace.getBlockById(parentId);
if (!parentBlock) {
console.warn("Can't connect to non-existant block: " + parentId);
console.warn("Can't connect to non-existent block: " + parentId);
return;
}
}
@@ -852,7 +852,7 @@ Blockly.Events.Move.prototype.run = function(forward) {
if (parentConnection) {
blockConnection.connect(parentConnection);
} else {
console.warn("Can't connect to non-existant input: " + inputName);
console.warn("Can't connect to non-existent input: " + inputName);
}
}
};
@@ -861,8 +861,8 @@ Blockly.Events.Move.prototype.run = function(forward) {
* Class for a UI event.
* @param {Blockly.Block} block The affected block.
* @param {string} element One of 'selected', 'comment', 'mutator', etc.
* @param {string} oldValue Previous value of element.
* @param {string} newValue New value of element.
* @param {*} oldValue Previous value of element.
* @param {*} newValue New value of element.
* @extends {Blockly.Events.Abstract}
* @constructor
*/

View File

@@ -309,7 +309,7 @@ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) {
* reported as warnings in the console, and are never fatal.
* @param {string} dropdownName The name of the field whose value is the key
* to the lookup table.
* @param {!Object<string, string>} lookupTable The table of field values to
* @param {!Object.<string, string>} lookupTable The table of field values to
* tooltip text.
* @return {Function} The extension function.
*/
@@ -369,7 +369,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName,
* Emits console warnings when they are not.
* @param {!Blockly.Block} block The block containing the dropdown
* @param {string} dropdownName The name of the dropdown
* @param {!Object<string, string>} lookupTable The string lookup table
* @param {!Object.<string, string>} lookupTable The string lookup table
* @private
*/
Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName,

View File

@@ -146,7 +146,7 @@ Blockly.Field.prototype.init = function() {
'ry': 4,
'x': -Blockly.BlockSvg.SEP_SPACE_X / 2,
'y': 0,
'height': 16}, this.fieldGroup_, this.sourceBlock_.workspace);
'height': 16}, this.fieldGroup_);
/** @type {!Element} */
this.textElement_ = Blockly.utils.createSvgElement('text',
{'class': 'blocklyText', 'y': this.size_.height - 12.5},

View File

@@ -29,6 +29,7 @@ goog.provide('Blockly.FieldNumber');
goog.require('Blockly.FieldTextInput');
goog.require('goog.math');
/**
* Class for an editable number field.
* @param {(string|number)=} opt_value The initial content of the field. The value

View File

@@ -41,8 +41,8 @@ goog.require('goog.string');
* a unique variable name will be generated.
* @param {Function=} opt_validator A function that is executed when a new
* option is selected. Its sole argument is the new option value.
* @param {Array.<string>} opt_variableTypes A list of the types of variables to
* include in the dropdown.
* @param {Array.<string>=} opt_variableTypes A list of the types of variables
* to include in the dropdown.
* @extends {Blockly.FieldDropdown}
* @constructor
*/
@@ -118,7 +118,7 @@ Blockly.FieldVariable.prototype.setValue = function(value) {
newText = variable.name;
}
// TODO(marisaleung): Remove name lookup after converting all Field Variable
// instances to use id instead of name.
// instances to use ID instead of name.
else if (variable = this.sourceBlock_.workspace.getVariable(value)) {
newValue = variable.getId();
}
@@ -217,7 +217,7 @@ Blockly.FieldVariable.dropdownCreate = function() {
*/
Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) {
var id = menuItem.getValue();
// TODO(marisaleung): change setValue() to take in an id as the parameter.
// TODO(marisaleung): change setValue() to take in an ID as the parameter.
// Then remove itemText.
var itemText;
if (this.sourceBlock_ && this.sourceBlock_.workspace) {

View File

@@ -353,7 +353,7 @@ Blockly.HorizontalFlyout.prototype.getClientRect = function() {
/**
* Compute height of flyout. Position button under each block.
* For RTL: Lay out the blocks right-aligned.
* @param {!Array<!Blockly.Block>} blocks The blocks to reflow.
* @param {!Array.<!Blockly.Block>} blocks The blocks to reflow.
* @private
*/
Blockly.HorizontalFlyout.prototype.reflowInternal_ = function(blocks) {

View File

@@ -328,7 +328,7 @@ Blockly.VerticalFlyout.prototype.getClientRect = function() {
/**
* Compute width of flyout. Position button under each block.
* For RTL: Lay out the blocks right-aligned.
* @param {!Array<!Blockly.Block>} blocks The blocks to reflow.
* @param {!Array.<!Blockly.Block>} blocks The blocks to reflow.
* @private
*/
Blockly.VerticalFlyout.prototype.reflowInternal_ = function(blocks) {

View File

@@ -121,7 +121,7 @@ Blockly.Grid.prototype.getSpacing = function() {
/**
* Get the id of the pattern element, which should be randomized to avoid
* conflicts with other Blockly instances on the page.
* @return {string} The pattern id.
* @return {string} The pattern ID.
* @package
*/
Blockly.Grid.prototype.getPatternId = function() {

View File

@@ -101,7 +101,7 @@ Blockly.Input.prototype.insertFieldAt = function(index, field, opt_name) {
// Empty string, Null or undefined generates no field, unless field is named.
if (!field && !opt_name) {
return this;
return index;
}
// Generate a FieldLabel when given a plain text field.
if (goog.isString(field)) {

View File

@@ -42,7 +42,7 @@ goog.getMsgOrig = goog.getMsg;
* Overrides the default Closure function to check for a Blockly.Msg first.
* Used infrequently, only known case is TODAY button in date picker.
* @param {string} str Translatable string, places holders in the form {$foo}.
* @param {Object<string, string>=} opt_values Maps place holder name to value.
* @param {Object.<string, string>=} opt_values Maps place holder name to value.
* @return {string} message with placeholders filled.
* @suppress {duplicate}
*/

View File

@@ -30,6 +30,7 @@ goog.provide('Blockly.ScrollbarPair');
goog.require('goog.dom');
goog.require('goog.events');
/**
* A note on units: most of the numbers that are in CSS pixels are scaled if the
* scrollbar is in a mutator.
@@ -189,7 +190,7 @@ Blockly.ScrollbarPair.prototype.getRatio_ = function(handlePosition, viewSize) {
* @param {!Blockly.Workspace} workspace Workspace to bind the scrollbar to.
* @param {boolean} horizontal True if horizontal, false if vertical.
* @param {boolean=} opt_pair True if scrollbar is part of a horiz/vert pair.
* @param {string} opt_class A class to be applied to this scrollbar.
* @param {string=} opt_class A class to be applied to this scrollbar.
* @constructor
*/
Blockly.Scrollbar = function(workspace, horizontal, opt_pair, opt_class) {
@@ -591,7 +592,7 @@ Blockly.Scrollbar.prototype.resizeContentVertical = function(hostMetrics) {
/**
* Create all the DOM elements required for a scrollbar.
* The resulting widget is not sized.
* @param {string} opt_class A class to be applied to this scrollbar.
* @param {string=} opt_class A class to be applied to this scrollbar.
* @private
*/
Blockly.Scrollbar.prototype.createDom_ = function(opt_class) {

View File

@@ -331,12 +331,12 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
// Decode the colour for any potential message references
// (eg. `%{BKY_MATH_HUE}`).
var colour = Blockly.utils.replaceMessageReferences(
childIn.getAttribute('colour'));
childIn.getAttribute('colour'));
if (goog.isString(colour)) {
if (colour.match(/^#[0-9a-fA-F]{6}$/)) {
if (/^#[0-9a-fA-F]{6}$/.test(colour)) {
childOut.hexColour = colour;
} else {
childOut.hexColour = Blockly.hueToRgb(colour);
childOut.hexColour = Blockly.hueToRgb(Number(colour));
}
this.hasColours_ = true;
} else {
@@ -388,7 +388,7 @@ Blockly.Toolbox.prototype.syncTrees_ = function(treeIn, treeOut, pathToMedia) {
/**
* Recursively add colours to this toolbox.
* @param {Blockly.Toolbox.TreeNode} opt_tree Starting point of tree.
* @param {Blockly.Toolbox.TreeNode=} opt_tree Starting point of tree.
* Defaults to the root node.
* @private
*/
@@ -695,6 +695,6 @@ Blockly.Toolbox.TreeNode.prototype.onKeyDown = function(e) {
* @extends {Blockly.Toolbox.TreeNode}
*/
Blockly.Toolbox.TreeSeparator = function(config) {
Blockly.Toolbox.TreeNode.call(this, null, '', config);
Blockly.Toolbox.TreeNode.call(this, null, goog.html.SafeHtml.EMPTY, config);
};
goog.inherits(Blockly.Toolbox.TreeSeparator, Blockly.Toolbox.TreeNode);

View File

@@ -34,9 +34,10 @@ goog.require('goog.events');
goog.require('goog.events.BrowserFeature');
goog.require('goog.string');
/**
* Which touch events are we currently paying attention to?
* @type {DOMString}
* @type {?string}
* @private
*/
Blockly.Touch.touchIdentifier_ = null;
@@ -63,7 +64,7 @@ Blockly.longPid_ = 0;
/**
* Context menus on touch devices are activated using a long-press.
* Unfortunately the contextmenu touch event is currently (2015) only suported
* Unfortunately the contextmenu touch event is currently (2015) only supported
* by Chrome. This function is fired on any touchstart event, queues a task,
* which after about a second opens the context menu. The tasks is killed
* if the touch event terminates early.
@@ -154,7 +155,7 @@ Blockly.Touch.getTouchIdentifierFromEvent = function(e) {
Blockly.Touch.checkTouchIdentifier = function(e) {
var identifier = Blockly.Touch.getTouchIdentifierFromEvent(e);
// if (Blockly.touchIdentifier_ )is insufficient because android touch
// if (Blockly.touchIdentifier_ )is insufficient because Android touch
// identifiers may be zero.
if (Blockly.Touch.touchIdentifier_ != undefined &&
Blockly.Touch.touchIdentifier_ != null) {

View File

@@ -30,6 +30,7 @@
**/
goog.provide('Blockly.utils.uiMenu');
/**
* Get the size of a rendered goog.ui.Menu.
* @param {!goog.ui.Menu} menu The menu to measure.

View File

@@ -45,7 +45,7 @@ goog.require('goog.userAgent');
* accessed through the exact name that was exported. Note, that all the exports
* are happening as the last thing in the generated js files, so they won't be
* accessible before JavaScript loads!
* @return {!Object<string, string>} The message array.
* @return {!Object.<string, string>} The message array.
* @private
*/
Blockly.utils.getMessageArray_ = function() {
@@ -285,11 +285,9 @@ Blockly.utils.getRelativeXY.XY_2D_REGEX_ =
* @param {string} name Element's tag name.
* @param {!Object} attrs Dictionary of attribute names and values.
* @param {Element} parent Optional parent on which to append the element.
* @param {Blockly.Workspace=} opt_workspace Optional workspace for access to
* context (scale...).
* @return {!SVGElement} Newly created SVG element.
*/
Blockly.utils.createSvgElement = function(name, attrs, parent /*, opt_workspace */) {
Blockly.utils.createSvgElement = function(name, attrs, parent) {
var e = /** @type {!SVGElement} */ (
document.createElementNS(Blockly.SVG_NS, name));
for (var key in attrs) {
@@ -327,7 +325,7 @@ Blockly.utils.isRightButton = function(e) {
* @param {!Event} e Mouse event.
* @param {!Element} svg SVG element.
* @param {SVGMatrix} matrix Inverted screen CTM to use.
* @return {!Object} Object with .x and .y properties.
* @return {!SVGPoint} Object with .x and .y properties.
*/
Blockly.utils.mouseToSvg = function(e, svg, matrix) {
var svgPoint = svg.createSVGPoint();
@@ -453,7 +451,7 @@ Blockly.utils.replaceMessageReferences = function(message) {
var interpolatedResult = Blockly.utils.tokenizeInterpolation_(message, false);
// When parseInterpolationTokens == false, interpolatedResult should be at
// most length 1.
return interpolatedResult.length ? interpolatedResult[0] : "";
return interpolatedResult.length ? interpolatedResult[0] : '';
};
/**
@@ -509,7 +507,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message,
// 0 - Base case.
// 1 - % found.
// 2 - Digit found.
// 3 - Message ref found
// 3 - Message ref found.
var state = 0;
var buffer = [];
var number = null;

View File

@@ -26,6 +26,7 @@
goog.provide('Blockly.VariableMap');
/**
* Class for a variable map. This contains a dictionary data structure with
* variable types as keys and lists of variables as values. The list of
@@ -38,7 +39,7 @@ goog.provide('Blockly.VariableMap');
* A map from variable type to list of variable names. The lists contain all
* of the named variables in the workspace, including variables
* that are not currently in use.
* @type {!Object<string, !Array.<Blockly.VariableModel>>}
* @type {!Object.<string, !Array.<Blockly.VariableModel>>}
* @private
*/
this.variableMap_ = {};
@@ -59,7 +60,7 @@ Blockly.VariableMap.prototype.clear = function() {
/**
* Rename the given variable by updating its name in the variable map.
* @param {?Blockly.VariableModel} variable Variable to rename.
* @param {Blockly.VariableModel} variable Variable to rename.
* @param {string} newName New variable name.
*/
Blockly.VariableMap.prototype.renameVariable = function(variable, newName) {
@@ -103,17 +104,18 @@ Blockly.VariableMap.prototype.renameVariable = function(variable, newName) {
};
/**
* Create a variable with a given name, optional type, and optional id.
* @param {!string} name The name of the variable. This must be unique across
* Create a variable with a given name, optional type, and optional ID.
* @param {string} name The name of the variable. This must be unique across
* variables and procedures.
* @param {?string} opt_type The type of the variable like 'int' or 'string'.
* @param {string=} opt_type The type of the variable like 'int' or 'string'.
* Does not need to be unique. Field_variable can filter variables based on
* their type. This will default to '' which is a specific type.
* @param {?string} opt_id The unique id of the variable. This will default to
* @param {string=} opt_id The unique ID of the variable. This will default to
* a UUID.
* @return {?Blockly.VariableModel} The newly created variable.
* @return {Blockly.VariableModel} The newly created variable.
*/
Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id) {
Blockly.VariableMap.prototype.createVariable = function(name,
opt_type, opt_id) {
var variable = this.getVariable(name);
if (variable) {
if (opt_type && variable.type != opt_type) {
@@ -122,11 +124,11 @@ Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id)
'type, "' + opt_type + '".');
}
if (opt_id && variable.getId() != opt_id) {
throw Error('Variable "' + name + '" is already in use and its id is "'
+ variable.getId() + '" which conflicts with the passed in ' +
throw Error('Variable "' + name + '" is already in use and its id is "' +
variable.getId() + '" which conflicts with the passed in ' +
'id, "' + opt_id + '".');
}
// The variable already exists and has the same id and type.
// The variable already exists and has the same ID and type.
return variable;
}
if (opt_id && this.getVariableById(opt_id)) {
@@ -148,7 +150,7 @@ Blockly.VariableMap.prototype.createVariable = function(name, opt_type, opt_id)
/**
* Delete a variable.
* @param {Blockly.VariableModel} variable Variable to delete.
* @param {!Blockly.VariableModel} variable Variable to delete.
*/
Blockly.VariableMap.prototype.deleteVariable = function(variable) {
var variableList = this.variableMap_[variable.type];
@@ -164,8 +166,8 @@ Blockly.VariableMap.prototype.deleteVariable = function(variable) {
/**
* Find the variable by the given name and return it. Return null if it is not
* found.
* @param {!string} name The name to check for.
* @return {?Blockly.VariableModel} The variable with the given name, or null if
* @param {string} name The name to check for.
* @return {Blockly.VariableModel} The variable with the given name, or null if
* it was not found.
*/
Blockly.VariableMap.prototype.getVariable = function(name) {
@@ -182,10 +184,10 @@ Blockly.VariableMap.prototype.getVariable = function(name) {
};
/**
* Find the variable by the given id and return it. Return null if it is not
* Find the variable by the given ID and return it. Return null if it is not
* found.
* @param {!string} id The id to check for.
* @return {?Blockly.VariableModel} The variable with the given id.
* @param {string} id The ID to check for.
* @return {Blockly.VariableModel} The variable with the given ID.
*/
Blockly.VariableMap.prototype.getVariableById = function(id) {
var keys = Object.keys(this.variableMap_);
@@ -204,7 +206,7 @@ Blockly.VariableMap.prototype.getVariableById = function(id) {
* Get a list containing all of the variables of a specified type. If type is
* null, return list of variables with empty string type.
* @param {?string} type Type of the variables to find.
* @return {Array.<Blockly.VariableModel>} The sought after variables of the
* @return {!Array.<!Blockly.VariableModel>} The sought after variables of the
* passed in type. An empty array if none are found.
*/
Blockly.VariableMap.prototype.getVariablesOfType = function(type) {
@@ -226,7 +228,7 @@ Blockly.VariableMap.prototype.getVariableTypes = function() {
/**
* Return all variables of all types.
* @return {!Array.<Blockly.VariableModel>} List of variable models.
* @return {!Array.<!Blockly.VariableModel>} List of variable models.
*/
Blockly.VariableMap.prototype.getAllVariables = function() {
var all_variables = [];

View File

@@ -31,14 +31,14 @@ goog.require('goog.string');
/**
* Class for a variable model.
* Holds information for the variable including name, id, and type.
* Holds information for the variable including name, ID, and type.
* @param {!Blockly.Workspace} workspace The variable's workspace.
* @param {!string} name The name of the variable. This must be unique across
* variables and procedures.
* @param {?string} opt_type The type of the variable like 'int' or 'string'.
* @param {string=} opt_type The type of the variable like 'int' or 'string'.
* Does not need to be unique. Field_variable can filter variables based on
* their type. This will default to '' which is a specific type.
* @param {?string} opt_id The unique id of the variable. This will default to
* @param {string=} opt_id The unique ID of the variable. This will default to
* a UUID.
* @see {Blockly.FieldVariable}
* @constructor
@@ -80,7 +80,7 @@ Blockly.VariableModel = function(workspace, name, opt_type, opt_id) {
};
/**
* @return {!string} The id for the variable.
* @return {!string} The ID for the variable.
*/
Blockly.VariableModel.prototype.getId = function() {
return this.id_;

View File

@@ -232,7 +232,7 @@ Blockly.Variables.generateUniqueName = function(workspace) {
* @param {function(?string=)=} opt_callback A callback. It will
* be passed an acceptable new variable name, or null if change is to be
* aborted (cancel button), or undefined if an existing variable was chosen.
* @param {?string} opt_type The type of the variable like 'int', 'string', or
* @param {string=} opt_type The type of the variable like 'int', 'string', or
* ''. This will default to '', which is a specific type.
*/
Blockly.Variables.createVariable = function(workspace, opt_callback, opt_type) {

View File

@@ -34,7 +34,7 @@ goog.require('goog.math');
/**
* Class for a workspace. This is a data structure that contains blocks.
* There is no UI, and can be created headlessly.
* @param {Blockly.Options} opt_options Dictionary of options.
* @param {!Blockly.Options=} opt_options Dictionary of options.
* @constructor
*/
Blockly.Workspace = function(opt_options) {
@@ -285,8 +285,8 @@ Blockly.Workspace.prototype.renameVariable = function(oldName, newName) {
/**
* Rename a variable by updating its name in the variable map. Identify the
* variable to rename with the given id.
* @param {string} id Id of the variable to rename.
* variable to rename with the given ID.
* @param {string} id ID of the variable to rename.
* @param {string} newName New variable name.
*/
Blockly.Workspace.prototype.renameVariableById = function(id, newName) {
@@ -295,13 +295,13 @@ Blockly.Workspace.prototype.renameVariableById = function(id, newName) {
};
/**
* Create a variable with a given name, optional type, and optional id.
* Create a variable with a given name, optional type, and optional ID.
* @param {!string} name The name of the variable. This must be unique across
* variables and procedures.
* @param {?string} opt_type The type of the variable like 'int' or 'string'.
* @param {string=} opt_type The type of the variable like 'int' or 'string'.
* Does not need to be unique. Field_variable can filter variables based on
* their type. This will default to '' which is a specific type.
* @param {?string} opt_id The unique id of the variable. This will default to
* @param {string=} opt_id The unique ID of the variable. This will default to
* a UUID.
* @return {?Blockly.VariableModel} The newly created variable.
*/
@@ -358,7 +358,8 @@ Blockly.Workspace.prototype.deleteVariable = function(name) {
if (uses.length > 1) {
// Confirm before deleting multiple blocks.
Blockly.confirm(
Blockly.Msg.DELETE_VARIABLE_CONFIRMATION.replace('%1', uses.length).
Blockly.Msg.DELETE_VARIABLE_CONFIRMATION.replace('%1',
String(uses.length)).
replace('%2', name),
function(ok) {
if (ok) {
@@ -372,23 +373,23 @@ Blockly.Workspace.prototype.deleteVariable = function(name) {
};
/**
* Delete a variables by the passed in id and all of its uses from this
* Delete a variables by the passed in ID and all of its uses from this
* workspace. May prompt the user for confirmation.
* @param {string} id Id of variable to delete.
* @param {string} id ID of variable to delete.
*/
Blockly.Workspace.prototype.deleteVariableById = function(id) {
var variable = this.getVariableById(id);
if (variable) {
this.deleteVariableInternal_(variable);
} else {
console.warn("Can't delete non-existant variable: " + id);
console.warn("Can't delete non-existent variable: " + id);
}
};
/**
* Deletes a variable and all of its uses from this workspace without asking the
* user for confirmation.
* @param {Blockly.VariableModel} variable Variable to delete.
* @param {!Blockly.VariableModel} variable Variable to delete.
* @private
*/
Blockly.Workspace.prototype.deleteVariableInternal_ = function(variable) {
@@ -426,10 +427,10 @@ Blockly.Workspace.prototype.getVariable = function(name) {
};
/**
* Find the variable by the given id and return it. Return null if it is not
* Find the variable by the given ID and return it. Return null if it is not
* found.
* @param {!string} id The id to check for.
* @return {?Blockly.VariableModel} The variable with the given id.
* @param {!string} id The ID to check for.
* @return {?Blockly.VariableModel} The variable with the given ID.
*/
Blockly.Workspace.prototype.getVariableById = function(id) {
return this.variableMap_.getVariableById(id);
@@ -450,7 +451,7 @@ Blockly.Workspace.prototype.getWidth = function() {
* @param {?string} prototypeName Name of the language object containing
* type-specific functions for this block.
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new id.
* create a new ID.
* @return {!Blockly.Block} The created block.
*/
Blockly.Workspace.prototype.newBlock = function(prototypeName, opt_id) {

View File

@@ -27,10 +27,12 @@
goog.provide('Blockly.WorkspaceAudio');
/**
* Class for loading, storing, and playing audio for a workspace.
* @param {Blockly.WorkspaceSvg} parentWorkspace The parent of the workspace
* this audio object belongs to, or null.
* @constructor
*/
Blockly.WorkspaceAudio = function(parentWorkspace) {
@@ -107,7 +109,7 @@ Blockly.WorkspaceAudio.prototype.load = function(filenames, name) {
Blockly.WorkspaceAudio.prototype.preload = function() {
for (var name in this.SOUNDS_) {
var sound = this.SOUNDS_[name];
sound.volume = .01;
sound.volume = 0.01;
sound.play();
sound.pause();
// iOS can only process one sound at a time. Trying to load more than one

View File

@@ -245,7 +245,7 @@ Blockly.WorkspaceSvg.prototype.lastRecordedPageScroll_ = null;
/**
* Map from function names to callbacks, for deciding what to do when a button
* is clicked.
* @type {!Object<string, function(!Blockly.FlyoutButton)>}
* @type {!Object.<string, function(!Blockly.FlyoutButton)>}
* @private
*/
Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_ = {};
@@ -253,7 +253,7 @@ Blockly.WorkspaceSvg.prototype.flyoutButtonCallbacks_ = {};
/**
* Map from function names to callbacks, for deciding what to do when a custom
* toolbox category is opened.
* @type {!Object<string, function(!Blockly.Workspace):!Array<!Element>>}
* @type {!Object.<string, function(!Blockly.Workspace):!Array.<!Element>>}
* @private
*/
Blockly.WorkspaceSvg.prototype.toolboxCategoryCallbacks_ = {};
@@ -370,10 +370,10 @@ Blockly.WorkspaceSvg.prototype.createDom = function(opt_backgroundClass) {
}
/** @type {SVGElement} */
this.svgBlockCanvas_ = Blockly.utils.createSvgElement('g',
{'class': 'blocklyBlockCanvas'}, this.svgGroup_, this);
{'class': 'blocklyBlockCanvas'}, this.svgGroup_);
/** @type {SVGElement} */
this.svgBubbleCanvas_ = Blockly.utils.createSvgElement('g',
{'class': 'blocklyBubbleCanvas'}, this.svgGroup_, this);
{'class': 'blocklyBubbleCanvas'}, this.svgGroup_);
var bottom = Blockly.Scrollbar.scrollbarThickness;
if (this.options.hasTrashcan) {
bottom = this.addTrashcan_(bottom);
@@ -652,7 +652,7 @@ Blockly.WorkspaceSvg.prototype.getBubbleCanvas = function() {
/**
* Get the SVG element that contains this workspace.
* @return {!Element} SVG element.
* @return {Element} SVG element.
*/
Blockly.WorkspaceSvg.prototype.getParentSvg = function() {
if (this.cachedParentSvg_) {
@@ -664,7 +664,7 @@ Blockly.WorkspaceSvg.prototype.getParentSvg = function() {
this.cachedParentSvg_ = element;
return element;
}
element = element.parentNode;
element = element.parentElement;
}
return null;
};
@@ -933,7 +933,7 @@ Blockly.WorkspaceSvg.prototype.renameVariable = function(oldName, newName) {
/**
* Rename a variable by updating its name in the variable map. Update the
* flyout to show the renamed variable immediately.
* @param {string} id Id of the variable to rename.
* @param {string} id ID of the variable to rename.
* @param {string} newName New variable name.
* @package
*/
@@ -954,9 +954,9 @@ Blockly.WorkspaceSvg.prototype.deleteVariable = function(name) {
};
/**
* Delete a variable by the passed in id. Update the flyout to show
* Delete a variable by the passed in ID. Update the flyout to show
* immediately that the variable is deleted.
* @param {string} id Id of variable to delete.
* @param {string} id ID of variable to delete.
* @package
*/
Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) {
@@ -971,7 +971,7 @@ Blockly.WorkspaceSvg.prototype.deleteVariableById = function(id) {
* @param {string=} opt_type The type of the variable like 'int' or 'string'.
* Does not need to be unique. Field_variable can filter variables based on
* their type. This will default to '' which is a specific type.
* @param {string=} opt_id The unique id of the variable. This will default to
* @param {string=} opt_id The unique ID of the variable. This will default to
* a UUID.
* @return {?Blockly.VariableModel} The newly created variable.
* @package
@@ -1064,7 +1064,7 @@ Blockly.WorkspaceSvg.prototype.moveDrag = function(e) {
* @return {boolean} True if currently dragging or scrolling.
*/
Blockly.WorkspaceSvg.prototype.isDragging = function() {
return this.currentGesture_ && this.currentGesture_.isDragging();
return this.currentGesture_ != null && this.currentGesture_.isDragging();
};
/**
@@ -1785,7 +1785,7 @@ Blockly.WorkspaceSvg.prototype.removeButtonCallback = function(key) {
* custom toolbox categories in this workspace. See the variable and procedure
* categories as an example.
* @param {string} key The name to use to look up this function.
* @param {function(!Blockly.Workspace):!Array<!Element>} func The function to
* @param {function(!Blockly.Workspace):!Array.<!Element>} func The function to
* call when the given toolbox category is opened.
*/
Blockly.WorkspaceSvg.prototype.registerToolboxCategoryCallback = function(key,
@@ -1799,7 +1799,7 @@ Blockly.WorkspaceSvg.prototype.registerToolboxCategoryCallback = function(key,
* Get the callback function associated with a given key, for populating
* custom toolbox categories in this workspace.
* @param {string} key The name to use to look up the function.
* @return {?function(!Blockly.Workspace):!Array<!Element>} The function
* @return {?function(!Blockly.Workspace):!Array.<!Element>} The function
* corresponding to the given key for this workspace, or null if no function
* is registered.
*/

View File

@@ -37,7 +37,7 @@ goog.require('goog.dom');
/**
* Encode a block tree as XML.
* @param {!Blockly.Workspace} workspace The workspace containing blocks.
* @param {boolean} opt_noId True if the encoder should skip the block ids.
* @param {boolean=} opt_noId True if the encoder should skip the block IDs.
* @return {!Element} XML document.
*/
Blockly.Xml.workspaceToDom = function(workspace, opt_noId) {
@@ -70,7 +70,7 @@ Blockly.Xml.variablesToDom = function(variableList) {
/**
* Encode a block subtree as XML with XY coordinates.
* @param {!Blockly.Block} block The root block to encode.
* @param {boolean} opt_noId True if the encoder should skip the block id.
* @param {boolean=} opt_noId True if the encoder should skip the block ID.
* @return {!Element} Tree of XML elements.
*/
Blockly.Xml.blockToDomWithXY = function(block, opt_noId) {
@@ -89,7 +89,7 @@ Blockly.Xml.blockToDomWithXY = function(block, opt_noId) {
/**
* Encode a block subtree as XML.
* @param {!Blockly.Block} block The root block to encode.
* @param {boolean} opt_noId True if the encoder should skip the block id.
* @param {boolean=} opt_noId True if the encoder should skip the block ID.
* @return {!Element} Tree of XML elements.
*/
Blockly.Xml.blockToDom = function(block, opt_noId) {
@@ -303,7 +303,7 @@ Blockly.Xml.textToDom = function(text) {
* Decode an XML DOM and create blocks on the workspace.
* @param {!Element} xml XML DOM.
* @param {!Blockly.Workspace} workspace The workspace.
* @return {Array.<string>} An array containing new block ids.
* @return {Array.<string>} An array containing new block IDs.
*/
Blockly.Xml.domToWorkspace = function(xml, workspace) {
if (xml instanceof Blockly.Workspace) {
@@ -317,7 +317,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
if (workspace.RTL) {
width = workspace.getWidth();
}
var newBlockIds = []; // A list of block ids added by this call.
var newBlockIds = []; // A list of block IDs added by this call.
Blockly.Field.startCache();
// Safari 7.1.3 is known to provide node lists with extra references to
// children beyond the lists' length. Trust the length, do not use the
@@ -385,12 +385,12 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
* blocks immediately below prior blocks, aligned by their starting edge.
* @param {!Element} xml The XML DOM.
* @param {!Blockly.Workspace} workspace The workspace to add to.
* @return {Array.<string>} An array containing new block ids.
* @return {Array.<string>} An array containing new block IDs.
*/
Blockly.Xml.appendDomToWorkspace = function(xml, workspace) {
var bbox; //bounding box of the current blocks
// first check if we have a workspaceSvg otherwise the block have no shape
// and the position does not matter
var bbox; // Bounding box of the current blocks.
// First check if we have a workspaceSvg, otherwise the blocks have no shape
// and the position does not matter.
if (workspace.hasOwnProperty('scale')) {
var savetab = Blockly.BlockSvg.TAB_WIDTH;
try {
@@ -400,22 +400,22 @@ Blockly.Xml.appendDomToWorkspace = function(xml, workspace) {
Blockly.BlockSvg.TAB_WIDTH = savetab;
}
}
// load the new blocks into the workspace and get the ids of the new blocks
// Load the new blocks into the workspace and get the IDs of the new blocks.
var newBlockIds = Blockly.Xml.domToWorkspace(xml,workspace);
if (bbox && bbox.height) { // check if any previous block
var offsetY = 0; // offset to add to y of the new block
if (bbox && bbox.height) { // check if any previous block
var offsetY = 0; // offset to add to y of the new block
var offsetX = 0;
var farY = bbox.y + bbox.height; //bottom position
var topX = bbox.x; // x of bounding box
// check position of the new blocks
var newX = Infinity; // x of top corner
var newY = Infinity; // y of top corner
var farY = bbox.y + bbox.height; // bottom position
var topX = bbox.x; // x of bounding box
// Check position of the new blocks.
var newX = Infinity; // x of top corner
var newY = Infinity; // y of top corner
for (var i = 0; i < newBlockIds.length; i++) {
var blockXY = workspace.getBlockById(newBlockIds[i]).getRelativeToSurfaceXY();
if (blockXY.y < newY) {
newY = blockXY.y;
}
if (blockXY.x < newX) { //if we align also on x
if (blockXY.x < newX) { // if we align also on x
newX = blockXY.x;
}
}
@@ -530,21 +530,21 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
var input;
// Find any enclosed blocks or shadows in this tag.
var childBlockNode = null;
var childShadowNode = null;
var childBlockElement = null;
var childShadowElement = null;
for (var j = 0, grandchildNode; grandchildNode = xmlChild.childNodes[j];
j++) {
if (grandchildNode.nodeType == 1) {
if (grandchildNode.nodeName.toLowerCase() == 'block') {
childBlockNode = grandchildNode;
childBlockElement = /** @type {!Element} */ (grandchildNode);
} else if (grandchildNode.nodeName.toLowerCase() == 'shadow') {
childShadowNode = grandchildNode;
childShadowElement = /** @type {!Element} */ (grandchildNode);
}
}
}
// Use the shadow block if there is no child block.
if (!childBlockNode && childShadowNode) {
childBlockNode = childShadowNode;
if (!childBlockElement && childShadowElement) {
childBlockElement = childShadowElement;
}
var name = xmlChild.getAttribute('name');
@@ -589,8 +589,8 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
var text = xmlChild.textContent;
if (field instanceof Blockly.FieldVariable) {
// TODO (marisaleung): When we change setValue and getValue to
// interact with id's instead of names, update this so that we get
// the variable based on id instead of textContent.
// interact with IDs instead of names, update this so that we get
// the variable based on ID instead of textContent.
var type = xmlChild.getAttribute('variableType') || '';
var variable = workspace.getVariable(text);
if (!variable) {
@@ -619,11 +619,11 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
prototypeName);
break;
}
if (childShadowNode) {
input.connection.setShadowDom(childShadowNode);
if (childShadowElement) {
input.connection.setShadowDom(childShadowElement);
}
if (childBlockNode) {
blockChild = Blockly.Xml.domToBlockHeadless_(childBlockNode,
if (childBlockElement) {
blockChild = Blockly.Xml.domToBlockHeadless_(childBlockElement,
workspace);
if (blockChild.outputConnection) {
input.connection.connect(blockChild.outputConnection);
@@ -636,16 +636,16 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
}
break;
case 'next':
if (childShadowNode && block.nextConnection) {
block.nextConnection.setShadowDom(childShadowNode);
if (childShadowElement && block.nextConnection) {
block.nextConnection.setShadowDom(childShadowElement);
}
if (childBlockNode) {
if (childBlockElement) {
goog.asserts.assert(block.nextConnection,
'Next statement does not exist.');
// If there is more than one XML 'next' tag.
goog.asserts.assert(!block.nextConnection.isConnected(),
'Next statement is already connected.');
blockChild = Blockly.Xml.domToBlockHeadless_(childBlockNode,
blockChild = Blockly.Xml.domToBlockHeadless_(childBlockElement,
workspace);
goog.asserts.assert(blockChild.previousConnection,
'Next block does not have previous statement.');