diff --git a/blocks/logic.js b/blocks/logic.js index 8de2ae6d4..c5f156a81 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -468,7 +468,7 @@ Blockly.Constants.Logic.CONTROLS_IF_MUTATOR_MIXIN = { i++; } // Rebuild block. - for (var i = 1; i <= this.elseifCount_; i++) { + for (i = 1; i <= this.elseifCount_; i++) { this.appendValueInput('IF' + i) .setCheck('Boolean') .appendField(Blockly.Msg['CONTROLS_IF_MSG_ELSEIF']); diff --git a/blocks/procedures.js b/blocks/procedures.js index 591a751a1..1c29e7583 100644 --- a/blocks/procedures.js +++ b/blocks/procedures.js @@ -372,17 +372,18 @@ Blockly.Blocks['procedures_defnoreturn'] = { // Add options to create getters for each parameter. if (!this.isCollapsed()) { for (var i = 0; i < this.argumentVarModels_.length; i++) { - var option = {enabled: true}; + var argOption = {enabled: true}; var argVar = this.argumentVarModels_[i]; - var name = argVar.name; - option.text = Blockly.Msg['VARIABLES_SET_CREATE_GET'].replace('%1', name); + argOption.text = Blockly.Msg['VARIABLES_SET_CREATE_GET'] + .replace('%1', argVar.name); - var xmlField = Blockly.Variables.generateVariableFieldDom(argVar); - var xmlBlock = document.createElement('block'); - xmlBlock.setAttribute('type', 'variables_get'); - xmlBlock.appendChild(xmlField); - option.callback = Blockly.ContextMenu.callbackFactory(this, xmlBlock); - options.push(option); + var argXmlField = Blockly.Variables.generateVariableFieldDom(argVar); + var argXmlBlock = document.createElement('block'); + argXmlBlock.setAttribute('type', 'variables_get'); + argXmlBlock.appendChild(argXmlField); + argOption.callback = + Blockly.ContextMenu.callbackFactory(this, argXmlBlock); + options.push(argOption); } } }, diff --git a/core/block_svg.js b/core/block_svg.js index c340576be..a1d41800f 100644 --- a/core/block_svg.js +++ b/core/block_svg.js @@ -700,8 +700,8 @@ Blockly.BlockSvg.prototype.showContextMenu_ = function(e) { if (this.workspace.options.disable && this.isEditable()) { // Option to disable/enable block. var disableOption = { - text: this.disabled ? - Blockly.Msg['ENABLE_BLOCK'] : Blockly.Msg['DISABLE_BLOCK'], + text: this.isEnabled() ? + Blockly.Msg['DISABLE_BLOCK'] : Blockly.Msg['ENABLE_BLOCK'], enabled: !this.getInheritedDisabled(), callback: function() { var group = Blockly.Events.getGroup(); @@ -936,7 +936,7 @@ Blockly.BlockSvg.prototype.dispose = function(healStack, animate) { * Change the colour of a block. */ Blockly.BlockSvg.prototype.updateColour = function() { - if (this.disabled) { + if (!this.isEnabled()) { // Disabled blocks don't have colour. return; } @@ -999,7 +999,7 @@ Blockly.BlockSvg.prototype.setShadowColour_ = function() { * Enable or disable a block. */ Blockly.BlockSvg.prototype.updateDisabled = function() { - if (this.disabled || this.getInheritedDisabled()) { + if (!this.isEnabled() || this.getInheritedDisabled()) { var added = Blockly.utils.dom.addClass( /** @type {!Element} */ (this.svgGroup_), 'blocklyDisabled'); if (added) { diff --git a/core/blockly.js b/core/blockly.js index 832a6af42..e42ad533e 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -107,7 +107,7 @@ Blockly.clipboardTypeCounts_ = null; /** * Cached value for whether 3D is supported. - * @type {!boolean} + * @type {?boolean} * @private */ Blockly.cache3dSupported_ = null; @@ -181,9 +181,9 @@ Blockly.svgResize = function(workspace) { // TODO (https://github.com/google/blockly/issues/1998) handle cases where there // are multiple workspaces and non-main workspaces are able to accept input. Blockly.onKeyDown_ = function(e) { - var workspace = Blockly.mainWorkspace; - if (workspace.options.readOnly || Blockly.utils.isTargetInput(e) || - (workspace.rendered && !workspace.isVisible())) { + var mainWorkspace = Blockly.mainWorkspace; + if (mainWorkspace.options.readOnly || Blockly.utils.isTargetInput(e) || + (mainWorkspace.rendered && !mainWorkspace.isVisible())) { // No key actions on readonly workspaces. // When focused on an HTML text input widget, don't trap any keys. // Ignore keypresses on rendered workspaces that have been explicitly @@ -247,7 +247,7 @@ Blockly.onKeyDown_ = function(e) { } else if (e.keyCode == 90) { // 'z' for undo 'Z' is for redo. Blockly.hideChaff(); - workspace.undo(e.shiftKey); + mainWorkspace.undo(e.shiftKey); } } // Common code for delete and cut. diff --git a/core/bubble.js b/core/bubble.js index d5b9f31b1..fe72b2c64 100644 --- a/core/bubble.js +++ b/core/bubble.js @@ -374,7 +374,7 @@ Blockly.Bubble.prototype.registerResizeEvent = function(callback) { /** * Move this bubble to the top of the stack. - * @return {!boolean} Whether or not the bubble has been moved. + * @return {boolean} Whether or not the bubble has been moved. * @private */ Blockly.Bubble.prototype.promote_ = function() { diff --git a/core/field.js b/core/field.js index ecd8469cb..86fd29818 100644 --- a/core/field.js +++ b/core/field.js @@ -736,31 +736,19 @@ Blockly.Field.prototype.setValue = function(newValue) { var validatedValue = this.doClassValidation_(newValue); // Class validators might accidentally forget to return, we'll ignore that. - if (validatedValue !== undefined) { - newValue = validatedValue; - } - if (newValue === null) { - doLogging && console.log('invalid, return'); - this.doValueInvalid_(); - if (this.isDirty_) { - this.forceRerender(); - } + newValue = this.validate_(newValue, validatedValue); + if (newValue instanceof Error) { + doLogging && console.log('invalid class validation, return'); return; } var localValidator = this.getValidator(); if (localValidator) { - var validatedValue = localValidator.call(this, newValue); + validatedValue = localValidator.call(this, newValue); // Local validators might accidentally forget to return, we'll ignore that. - if (validatedValue !== undefined) { - newValue = validatedValue; - } - if (newValue === null) { - doLogging && console.log('invalid, return'); - this.doValueInvalid_(); - if (this.isDirty_) { - this.forceRerender(); - } + newValue = this.validate_(newValue, validatedValue); + if (newValue instanceof Error) { + doLogging && console.log('invalid local validation, return'); return; } } @@ -782,6 +770,27 @@ Blockly.Field.prototype.setValue = function(newValue) { doLogging && console.log(this.value_); }; +/** + * Process the result of validation. + * @param {*} newValue New value. + * @param {*} validatedValue Validated value. + * @return {*} New value, or an Error object. + * @private + */ +Blockly.Field.prototype.validate_ = function(newValue, validatedValue) { + if (validatedValue !== undefined) { + newValue = validatedValue; + } + if (newValue === null) { + this.doValueInvalid_(); + if (this.isDirty_) { + this.forceRerender(); + } + return Error(); + } + return newValue; +}; + /** * Get the current value of the field. * @return {*} Current value. diff --git a/core/field_date.js b/core/field_date.js index 730677bc2..20290fa68 100644 --- a/core/field_date.js +++ b/core/field_date.js @@ -36,7 +36,6 @@ goog.require('goog.date.DateTime'); goog.require('goog.events'); goog.require('goog.i18n.DateTimeSymbols'); goog.require('goog.i18n.DateTimeSymbols_he'); -goog.require('goog.style'); goog.require('goog.ui.DatePicker'); diff --git a/core/field_textinput.js b/core/field_textinput.js index df82ee4d6..a79d55e03 100644 --- a/core/field_textinput.js +++ b/core/field_textinput.js @@ -134,7 +134,7 @@ Blockly.FieldTextInput.prototype.doValueInvalid_ = function() { * Called by setValue if the text input is valid. Updates the value of the * field, and updates the text of the field if it is not currently being * edited (i.e. handled by the htmlInput_). - * @param {!string} newValue The new validated value of the field. + * @param {string} newValue The new validated value of the field. * @protected */ Blockly.FieldTextInput.prototype.doValueUpdate_ = function(newValue) { diff --git a/core/flyout_base.js b/core/flyout_base.js index e42798284..b92c6bcf8 100644 --- a/core/flyout_base.js +++ b/core/flyout_base.js @@ -608,7 +608,7 @@ Blockly.Flyout.prototype.onMouseDown_ = function(e) { * Does this flyout allow you to create a new instance of the given block? * Used for deciding if a block can be "dragged out of" the flyout. * @param {!Blockly.BlockSvg} block The block to copy from the flyout. - * @return {!boolean} True if you can create a new instance of the block, false + * @return {boolean} True if you can create a new instance of the block, false * otherwise. * @package */ diff --git a/core/options.js b/core/options.js index 9c71541f4..3775f2dcb 100644 --- a/core/options.js +++ b/core/options.js @@ -164,7 +164,7 @@ Blockly.Options.prototype.getMetrics = null; * Parse the user-specified move options, using reasonable defaults where * behaviour is unspecified. * @param {!Object} options Dictionary of options. - * @param {!boolean} hasCategories Whether the workspace has categories or not. + * @param {boolean} hasCategories Whether the workspace has categories or not. * @return {!Object} A dictionary of normalized options. * @private */ diff --git a/core/utils/coordinate.js b/core/utils/coordinate.js index 7d08362d3..21d6ca50f 100644 --- a/core/utils/coordinate.js +++ b/core/utils/coordinate.js @@ -94,8 +94,8 @@ Blockly.utils.Coordinate.magnitude = function(a) { /** * Returns the difference between two coordinates as a new * Blockly.utils.Coordinate. - * @param {!Blockly.utils.Coordinate} a A Coordinate. - * @param {!Blockly.utils.Coordinate} b A Coordinate. + * @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate. * @return {!Blockly.utils.Coordinate} A Coordinate representing the difference * between `a` and `b`. */ @@ -105,10 +105,10 @@ Blockly.utils.Coordinate.difference = function(a, b) { /** * Returns the sum of two coordinates as a new Blockly.utils.Coordinate. - * @param {!Blockly.utils.Coordinate} a A Coordinate. - * @param {!Blockly.utils.Coordinate} b A Coordinate. - * @return {!Blockly.utils.Coordinate} A Coordinate representing the sum of the two - * coordinates. + * @param {!Blockly.utils.Coordinate|!SVGPoint} a An x/y coordinate. + * @param {!Blockly.utils.Coordinate|!SVGPoint} b An x/y coordinate. + * @return {!Blockly.utils.Coordinate} A Coordinate representing the sum of + * the two coordinates. */ Blockly.utils.Coordinate.sum = function(a, b) { return new Blockly.utils.Coordinate(a.x + b.x, a.y + b.y); diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 52f7dae05..5fd0c8899 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1676,7 +1676,7 @@ Blockly.WorkspaceSvg.prototype.zoom = function(x, y, amount) { // Find the new scrollX/scrollY so that the center remains in the same // position (relative to the center) after we zoom. // newScale and matrix.a should be identical (within a rounding error). - var matrix = matrix.translate(x * (1 - scaleChange), y * (1 - scaleChange)) + matrix = matrix.translate(x * (1 - scaleChange), y * (1 - scaleChange)) .scale(scaleChange); // scrollX and scrollY are in pixels. // The scrollX and scrollY still need to have absoluteLeft and absoluteTop