diff --git a/blocks/logic.js b/blocks/logic.js index 6406f77a7..5899e04a5 100644 --- a/blocks/logic.js +++ b/blocks/logic.js @@ -295,8 +295,8 @@ Blockly.Constants.Logic.TOOLTIPS_BY_OP = { }; Blockly.Extensions.register('logic_op_tooltip', - Blockly.Extensions.buildTooltipForDropdown( - 'OP', Blockly.Constants.Logic.TOOLTIPS_BY_OP)); + Blockly.Extensions.buildTooltipForDropdown( + 'OP', Blockly.Constants.Logic.TOOLTIPS_BY_OP)); /** * Mutator methods added to controls_if blocks. @@ -486,7 +486,7 @@ Blockly.Constants.Logic.CONTROLS_IF_TOOLTIP_EXTENSION = function() { }; Blockly.Extensions.register('controls_if_tooltip', - Blockly.Constants.Logic.CONTROLS_IF_TOOLTIP_EXTENSION); + Blockly.Constants.Logic.CONTROLS_IF_TOOLTIP_EXTENSION); /** * Corrects the logic_compare dropdown label with respect to language direction. @@ -574,7 +574,7 @@ Blockly.Constants.Logic.LOGIC_COMPARE_EXTENSION = function() { }; Blockly.Extensions.register('logic_compare', - Blockly.Constants.Logic.LOGIC_COMPARE_EXTENSION); + Blockly.Constants.Logic.LOGIC_COMPARE_EXTENSION); /** * Adds type coordination between inputs and output. @@ -619,4 +619,4 @@ Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN = { }; Blockly.Extensions.registerMixin('logic_ternary', - Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN); + Blockly.Constants.Logic.LOGIC_TERNARY_ONCHANGE_MIXIN); diff --git a/blocks/loops.js b/blocks/loops.js index 7000636ec..24321bfec 100644 --- a/blocks/loops.js +++ b/blocks/loops.js @@ -227,8 +227,8 @@ Blockly.Constants.Loops.WHILE_UNTIL_TOOLTIPS = { }; Blockly.Extensions.register('controls_whileUntil_tooltip', - Blockly.Extensions.buildTooltipForDropdown( - 'MODE', Blockly.Constants.Loops.WHILE_UNTIL_TOOLTIPS)); + Blockly.Extensions.buildTooltipForDropdown( + 'MODE', Blockly.Constants.Loops.WHILE_UNTIL_TOOLTIPS)); /** * Tooltips for the 'controls_flow_statements' block, keyed by FLOW value. @@ -242,8 +242,8 @@ Blockly.Constants.Loops.BREAK_CONTINUE_TOOLTIPS = { }; Blockly.Extensions.register('controls_flow_tooltip', - Blockly.Extensions.buildTooltipForDropdown( - 'FLOW', Blockly.Constants.Loops.BREAK_CONTINUE_TOOLTIPS)); + Blockly.Extensions.buildTooltipForDropdown( + 'FLOW', Blockly.Constants.Loops.BREAK_CONTINUE_TOOLTIPS)); /** * Mixin to add a context menu item to create a 'variables_get' block. @@ -277,15 +277,15 @@ Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN = { }; Blockly.Extensions.registerMixin('contextMenu_newGetVariableBlock', - Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN); + Blockly.Constants.Loops.CUSTOM_CONTEXT_MENU_CREATE_VARIABLES_GET_MIXIN); Blockly.Extensions.register('controls_for_tooltip', - Blockly.Extensions.buildTooltipWithFieldValue( - Blockly.Msg.CONTROLS_FOR_TOOLTIP, 'VAR')); + Blockly.Extensions.buildTooltipWithFieldValue( + Blockly.Msg.CONTROLS_FOR_TOOLTIP, 'VAR')); Blockly.Extensions.register('controls_forEach_tooltip', - Blockly.Extensions.buildTooltipWithFieldValue( - Blockly.Msg.CONTROLS_FOREACH_TOOLTIP, 'VAR')); + Blockly.Extensions.buildTooltipWithFieldValue( + Blockly.Msg.CONTROLS_FOREACH_TOOLTIP, 'VAR')); /** * This mixin adds a check to make sure the 'controls_flow_statements' block @@ -339,4 +339,4 @@ Blockly.Constants.Loops.CONTROL_FLOW_CHECK_IN_LOOP_MIXIN = { }; Blockly.Extensions.registerMixin('controls_flow_in_loop_check', - Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN); + Blockly.Constants.Loops.CONTROL_FLOW_IN_LOOP_CHECK_MIXIN); diff --git a/blocks/math.js b/blocks/math.js index ca04dc728..8244618f9 100644 --- a/blocks/math.js +++ b/blocks/math.js @@ -422,8 +422,8 @@ Blockly.Constants.Math.TOOLTIPS_BY_OP = { }; Blockly.Extensions.register('math_op_tooltip', - Blockly.Extensions.buildTooltipForDropdown( - 'OP', Blockly.Constants.Math.TOOLTIPS_BY_OP)); + Blockly.Extensions.buildTooltipForDropdown( + 'OP', Blockly.Constants.Math.TOOLTIPS_BY_OP)); /** @@ -489,8 +489,8 @@ Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION = function() { }; Blockly.Extensions.registerMutator('math_is_divisibleby_mutator', - Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN, - Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION); + Blockly.Constants.Math.IS_DIVISIBLEBY_MUTATOR_MIXIN, + Blockly.Constants.Math.IS_DIVISIBLE_MUTATOR_EXTENSION); /** * Update the tooltip of 'math_change' block to reference the variable. @@ -505,8 +505,8 @@ Blockly.Constants.Math.CHANGE_TOOLTIP_EXTENSION = function() { }; Blockly.Extensions.register('math_change_tooltip', - Blockly.Extensions.buildTooltipWithFieldValue( - Blockly.Msg.MATH_CHANGE_TOOLTIP, 'VAR')); + Blockly.Extensions.buildTooltipWithFieldValue( + Blockly.Msg.MATH_CHANGE_TOOLTIP, 'VAR')); /** * Mixin with mutator methods to support alternate output based if the @@ -563,5 +563,5 @@ Blockly.Constants.Math.LIST_MODES_MUTATOR_EXTENSION = function() { }; Blockly.Extensions.registerMutator('math_modes_of_list_mutator', - Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN, - Blockly.Constants.Math.LIST_MODES_MUTATOR_EXTENSION); + Blockly.Constants.Math.LIST_MODES_MUTATOR_MIXIN, + Blockly.Constants.Math.LIST_MODES_MUTATOR_EXTENSION); diff --git a/blocks/text.js b/blocks/text.js index 22dda35e8..3e0d62de9 100644 --- a/blocks/text.js +++ b/blocks/text.js @@ -876,18 +876,18 @@ Blockly.Constants.Text.TEXT_CHARAT_EXTENSION = function() { }; Blockly.Extensions.register('text_indexOf_tooltip', - Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION); + Blockly.Constants.Text.TEXT_INDEXOF_TOOLTIP_EXTENSION); Blockly.Extensions.register('text_quotes', - Blockly.Constants.Text.TEXT_QUOTES_EXTENSION); + Blockly.Constants.Text.TEXT_QUOTES_EXTENSION); Blockly.Extensions.register('text_append_tooltip', - Blockly.Constants.Text.TEXT_APPEND_TOOLTIP_EXTENSION); + Blockly.Constants.Text.TEXT_APPEND_TOOLTIP_EXTENSION); Blockly.Extensions.registerMutator('text_join_mutator', - Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN, - Blockly.Constants.Text.TEXT_JOIN_EXTENSION); + Blockly.Constants.Text.TEXT_JOIN_MUTATOR_MIXIN, + Blockly.Constants.Text.TEXT_JOIN_EXTENSION); Blockly.Extensions.registerMutator('text_charAt_mutator', - Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN, - Blockly.Constants.Text.TEXT_CHARAT_EXTENSION); \ No newline at end of file + Blockly.Constants.Text.TEXT_CHARAT_MUTATOR_MIXIN, + Blockly.Constants.Text.TEXT_CHARAT_EXTENSION); diff --git a/core/extensions.js b/core/extensions.js index 607ef0271..2ec647caa 100644 --- a/core/extensions.js +++ b/core/extensions.js @@ -83,14 +83,14 @@ Blockly.Extensions.registerMixin = function(name, mixinObj) { * decompose are defined on the mixin. * @param {string} name The name of this mutator extension. * @param {!Object} mixinObj The values to mix in. - * @param {(function())=} opt_helperFn An optional function to apply after mixing - * in the object. + * @param {(function())=} opt_helperFn An optional function to apply after + * mixing in the object. * @param {Array.=} opt_blockList A list of blocks to appear in the * flyout of the mutator dialog. * @throws {Error} if the mutation is invalid or can't be applied to the block. */ -Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, - opt_blockList) { +Blockly.Extensions.registerMutator = + function(name, mixinObj, opt_helperFn, opt_blockList) { var errorPrefix = 'Error when registering mutator "' + name + '": '; // Sanity check the mixin object before registering it. @@ -99,8 +99,8 @@ Blockly.Extensions.registerMutator = function(name, mixinObj, opt_helperFn, Blockly.Extensions.checkHasFunction_(errorPrefix, mixinObj.mutationToDom, 'mutationToDom'); - var hasMutatorDialog = Blockly.Extensions.checkMutatorDialog_(mixinObj, - errorPrefix); + var hasMutatorDialog = + Blockly.Extensions.checkMutatorDialog_(mixinObj, errorPrefix); if (opt_helperFn && !goog.isFunction(opt_helperFn)) { throw new Error('Extension "' + name + '" is not a function'); @@ -148,8 +148,8 @@ Blockly.Extensions.apply = function(name, block, isMutator) { Blockly.Extensions.checkBlockHasMutatorProperties_(errorPrefix, block); } else { if (!Blockly.Extensions.mutatorPropertiesMatch_(mutatorProperties, block)) { - throw new Error('Error when applying extension "' + name + - '": mutation properties changed when applying a non-mutator extension.'); + throw new Error('Error when applying extension "' + name + '": ' + + 'mutation properties changed when applying a non-mutator extension.'); } } }; @@ -162,14 +162,14 @@ Blockly.Extensions.apply = function(name, block, isMutator) { * @throws {Error} if the property does not exist or is not a function. * @private */ -Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func, - propertyName) { +Blockly.Extensions.checkHasFunction_ = + function(errorPrefix, func, propertyName) { if (!func) { throw new Error(errorPrefix + 'missing required property "' + propertyName + '"'); } else if (typeof func != 'function') { throw new Error(errorPrefix + - '" required property "' + propertyName + '" must be a function'); + '" required property "' + propertyName + '" must be a function'); } }; @@ -209,9 +209,9 @@ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { var hasDecompose = object.decompose !== undefined; if (hasCompose && hasDecompose) { - if (typeof object.compose !== 'function') { + if (typeof object.compose != 'function') { throw new Error(errorPrefix + 'compose must be a function.'); - } else if (typeof object.decompose !== 'function') { + } else if (typeof object.decompose != 'function') { throw new Error(errorPrefix + 'decompose must be a function.'); } return true; @@ -230,13 +230,15 @@ Blockly.Extensions.checkMutatorDialog_ = function(object, errorPrefix) { * @param {!Blockly.Block} block The block to inspect. * @private */ -Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix, - block) { - if (typeof block.domToMutation !== 'function') { - throw new Error(errorPrefix + 'Applying a mutator didn\'t add "domToMutation"'); +Blockly.Extensions.checkBlockHasMutatorProperties_ = + function(errorPrefix, block) { + if (typeof block.domToMutation != 'function') { + throw new Error(errorPrefix + + 'Applying a mutator didn\'t add "domToMutation"'); } - if (typeof block.mutationToDom !== 'function') { - throw new Error(errorPrefix + 'Applying a mutator didn\'t add "mutationToDom"'); + if (typeof block.mutationToDom != 'function') { + throw new Error(errorPrefix + + 'Applying a mutator didn\'t add "mutationToDom"'); } // A block with a mutator isn't required to have a mutation dialog, but @@ -280,19 +282,16 @@ Blockly.Extensions.getMutatorProperties_ = function(block) { * @private */ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { - var match = true; var newProperties = Blockly.Extensions.getMutatorProperties_(block); if (newProperties.length != oldProperties.length) { - match = false; - } else { - for (var i = 0; i < newProperties.length; i++) { - if (oldProperties[i] != newProperties[i]) { - match = false; - } + return false; + } + for (var i = 0; i < newProperties.length; i++) { + if (oldProperties[i] != newProperties[i]) { + return false; } } - - return match; + return true; }; /** @@ -314,7 +313,8 @@ Blockly.Extensions.mutatorPropertiesMatch_ = function(oldProperties, block) { * tooltip text. * @return {Function} The extension function. */ -Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, lookupTable) { +Blockly.Extensions.buildTooltipForDropdown = + function(dropdownName, lookupTable) { // List of block types already validated, to minimize duplicate warnings. var blockTypesChecked = []; @@ -338,7 +338,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, lookupTable) var extensionFn = function() { if (this.type && blockTypesChecked.indexOf(this.type) === -1) { Blockly.Extensions.checkDropdownOptionsInTable_( - this, dropdownName, lookupTable); + this, dropdownName, lookupTable); blockTypesChecked.push(this.type); } @@ -347,7 +347,7 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, lookupTable) var tooltip = lookupTable[value]; if (tooltip == null) { if (blockTypesChecked.indexOf(this.type) === -1) { - // Warn for missing values on generated tooltips + // Warn for missing values on generated tooltips. var warning = 'No tooltip mapping for value ' + value + ' of field ' + dropdownName; if (this.type != null) { @@ -373,20 +373,20 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName, lookupTable) * @private */ Blockly.Extensions.checkDropdownOptionsInTable_ = - function(block, dropdownName, lookupTable) { - // Validate all dropdown options have values. - var dropdown = block.getField(dropdownName); - if (!dropdown.isOptionListDynamic()) { - var options = dropdown.getOptions(); - for (var i = 0; i < options.length; ++i) { - var optionKey = options[i][1]; // label, then value - if (lookupTable[optionKey] == null) { - console.warn('No tooltip mapping for value ' + optionKey + - ' of field ' + dropdownName + ' of block type ' + block.type); - } + function(block, dropdownName, lookupTable) { + // Validate all dropdown options have values. + var dropdown = block.getField(dropdownName); + if (!dropdown.isOptionListDynamic()) { + var options = dropdown.getOptions(); + for (var i = 0; i < options.length; ++i) { + var optionKey = options[i][1]; // label, then value + if (lookupTable[optionKey] == null) { + console.warn('No tooltip mapping for value ' + optionKey + + ' of field ' + dropdownName + ' of block type ' + block.type); } } - }; + } +}; /** * Builds an extension function that will install a dynamic tooltip. The @@ -398,30 +398,30 @@ Blockly.Extensions.checkDropdownOptionsInTable_ = * @returns {Function} The extension function. */ Blockly.Extensions.buildTooltipWithFieldValue = - function(msgTemplate, fieldName) { - // Check the tooltip string messages for invalid references. - // Wait for load, in case Blockly.Msg is not yet populated. - // runAfterPageLoad() does not run in a Node.js environment due to lack of - // document object, in which case skip the validation. - if (document) { // Relies on document.readyState - Blockly.utils.runAfterPageLoad(function() { - // Will print warnings is reference is missing. - Blockly.utils.checkMessageReferences(msgTemplate); - }); - } + function(msgTemplate, fieldName) { + // Check the tooltip string messages for invalid references. + // Wait for load, in case Blockly.Msg is not yet populated. + // runAfterPageLoad() does not run in a Node.js environment due to lack of + // document object, in which case skip the validation. + if (document) { // Relies on document.readyState + Blockly.utils.runAfterPageLoad(function() { + // Will print warnings is reference is missing. + Blockly.utils.checkMessageReferences(msgTemplate); + }); + } - /** - * The actual extension. - * @this {Blockly.Block} - */ - var extensionFn = function() { - this.setTooltip(function() { - return Blockly.utils.replaceMessageReferences(msgTemplate) - .replace('%1', this.getFieldValue(fieldName)); - }.bind(this)); - }; - return extensionFn; + /** + * The actual extension. + * @this {Blockly.Block} + */ + var extensionFn = function() { + this.setTooltip(function() { + return Blockly.utils.replaceMessageReferences(msgTemplate) + .replace('%1', this.getFieldValue(fieldName)); + }.bind(this)); }; + return extensionFn; +}; /** * Configures the tooltip to mimic the parent block when connected. Otherwise, @@ -435,10 +435,8 @@ Blockly.Extensions.extensionParentTooltip_ = function() { this.tooltipWhenNotConnected_ = this.tooltip; this.setTooltip(function() { var parent = this.getParent(); - return (parent && - parent.getInputsInline() && - parent.tooltip) || - this.tooltipWhenNotConnected_; + return (parent && parent.getInputsInline() && parent.tooltip) || + this.tooltipWhenNotConnected_; }.bind(this)); }; Blockly.Extensions.register('parent_tooltip_when_inline', diff --git a/core/field_image.js b/core/field_image.js index 3960169a4..e9767f9c9 100644 --- a/core/field_image.js +++ b/core/field_image.js @@ -54,7 +54,7 @@ Blockly.FieldImage = function(src, width, height, opt_alt, opt_onClick) { this.text_ = opt_alt || ''; this.setValue(src); - if (typeof opt_onClick === "function") { + if (typeof opt_onClick == 'function') { this.clickHandler_ = opt_onClick; } }; diff --git a/core/utils.js b/core/utils.js index 62c150ea3..7b0a05a50 100644 --- a/core/utils.js +++ b/core/utils.js @@ -44,7 +44,7 @@ goog.require('goog.userAgent'); * is not possible. To access the exported Blockly.Msg.Something it needs to be * 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! + * accessible before JavaScript loads! * @return {!Object} * @private */ @@ -208,10 +208,9 @@ Blockly.utils.getRelativeXY = function(element) { Blockly.utils.getInjectionDivXY_ = function(element) { var x = 0; var y = 0; - var scale = 1; while (element) { var xy = Blockly.utils.getRelativeXY(element); - scale = Blockly.utils.getScale_(element); + var scale = Blockly.utils.getScale_(element); x = (x * scale) + xy.x; y = (y * scale) + xy.y; var classes = element.getAttribute('class') || ''; @@ -465,18 +464,18 @@ Blockly.utils.replaceMessageReferences = function(message) { * Otherwise, false. */ Blockly.utils.checkMessageReferences = function(message) { - var isValid = true; // True until a bad reference is found + var isValid = true; // True until a bad reference is found. var regex = /%{BKY_([a-zA-Z][a-zA-Z0-9_]*)}/g; var match = regex.exec(message); - while (match != null) { + while (match) { var msgKey = match[1]; - if (Blockly.utils.getMessageArray_()[msgKey] == null) { + if (Blockly.utils.getMessageArray_()[msgKey] == undefined) { console.log('WARNING: No message string for %{BKY_' + msgKey + '}.'); isValid = false; } - // Re-run on remainder of sting. + // Re-run on remainder of string. message = message.substring(match.index + msgKey.length + 1); match = regex.exec(message); } @@ -485,7 +484,7 @@ Blockly.utils.checkMessageReferences = function(message) { }; /** - * Internal implemention of the message reference and interpolation token + * Internal implementation of the message reference and interpolation token * parsing used by tokenizeInterpolation() and replaceMessageReferences(). * @param {string} message Text which might contain string table references and * interpolation tokens. @@ -494,7 +493,8 @@ Blockly.utils.checkMessageReferences = function(message) { * @return {!Array.} Array of strings and numbers. * @private */ -Blockly.utils.tokenizeInterpolation_ = function(message, parseInterpolationTokens) { +Blockly.utils.tokenizeInterpolation_ = + function(message, parseInterpolationTokens) { var tokens = []; var chars = message.split(''); chars.push(''); // End marker. @@ -640,7 +640,7 @@ Blockly.utils.genUid = function() { * Legal characters for the unique ID. Should be all on a US keyboard. * No characters that conflict with XML or JSON. Requests to remove additional * 'problematic' characters from this soup will be denied. That's your failure - * to properly escape in your own environment. Issues #251, #625, #682. + * to properly escape in your own environment. Issues #251, #625, #682, #1304. * @private */ Blockly.utils.genUid.soup_ = '!#$%()*+,-./:;=?@[]^_`{|}~' + @@ -937,4 +937,3 @@ Blockly.utils.getViewportBBox = function() { left: scrollOffset.x }; }; -