mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-13 06:29:31 -04:00
Style improvements. No functional changes. (#1367)
This commit is contained in:
parent
6fced52ef8
commit
d906095698
2 changed files with 41 additions and 32 deletions
|
@ -88,8 +88,8 @@ 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.<string>=} 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.
|
||||
|
@ -153,8 +153,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.');
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@ -174,7 +174,7 @@ Blockly.Extensions.checkHasFunction_ = function(errorPrefix, func,
|
|||
'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');
|
||||
}
|
||||
};
|
||||
|
||||
|
@ -214,9 +214,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;
|
||||
|
@ -240,8 +240,9 @@ Blockly.Extensions.checkBlockHasMutatorProperties_ = function(errorPrefix,
|
|||
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
|
||||
|
@ -285,19 +286,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;
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -343,7 +341,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);
|
||||
}
|
||||
|
||||
|
@ -352,7 +350,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) {
|
||||
|
@ -440,10 +438,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',
|
||||
|
|
|
@ -38,6 +38,20 @@ goog.require('goog.events.BrowserFeature');
|
|||
goog.require('goog.math.Coordinate');
|
||||
goog.require('goog.userAgent');
|
||||
|
||||
|
||||
/**
|
||||
* To allow ADVANCED_OPTIMIZATIONS, combining variable.name and variable['name']
|
||||
* 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!
|
||||
* @return {!Object<string, string>} The message array
|
||||
* @private
|
||||
*/
|
||||
Blockly.utils.getMessageArray_ = function() {
|
||||
return goog.global['Blockly']['Msg'];
|
||||
};
|
||||
|
||||
/**
|
||||
* Remove an attribute from a element even if it's in IE 10.
|
||||
* Similar to Element.removeAttribute() but it works on SVG elements in IE 10.
|
||||
|
@ -194,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') || '';
|
||||
|
@ -449,18 +462,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.Msg[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);
|
||||
}
|
||||
|
@ -469,7 +482,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.
|
||||
|
@ -624,7 +637,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_ = '!#$%()*+,-./:;=?@[]^_`{|}~' +
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue