mirror of
https://github.com/scratchfoundation/scratch-blocks.git
synced 2025-08-28 22:10:31 -04:00
More small stuff from google, and allow unused vars with _names
This commit is contained in:
parent
88bb0bff3e
commit
4fc5b6ac97
15 changed files with 157 additions and 120 deletions
11
.eslintrc
11
.eslintrc
|
@ -6,7 +6,16 @@
|
|||
"linebreak-style": ["error", "unix"],
|
||||
"max-len": ["error", 120, 4],
|
||||
"no-trailing-spaces": ["error", { "skipBlankLines": true }],
|
||||
"no-unused-vars": ["error", {"args": "after-used", "varsIgnorePattern": "^_"}],
|
||||
"no-unused-vars": [
|
||||
"error",
|
||||
{
|
||||
"args": "after-used",
|
||||
# Ignore vars starting with an underscore.
|
||||
"varsIgnorePattern": "^_",
|
||||
# Ignore arguments starting with an underscore.
|
||||
"argsIgnorePattern": "^_"
|
||||
}
|
||||
],
|
||||
"no-use-before-define": ["error"],
|
||||
"quotes": ["off"], # Blockly mixes single and double quotes
|
||||
"semi": ["error", "always"],
|
||||
|
|
|
@ -181,10 +181,10 @@ Blockly.Tooltip.onMouseOver_ = function(e) {
|
|||
|
||||
/**
|
||||
* Hide the tooltip if the mouse leaves the object and enters the workspace.
|
||||
* @param {!Event} e Mouse event.
|
||||
* @param {!Event} _e Mouse event.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Tooltip.onMouseOut_ = function(/*e*/) {
|
||||
Blockly.Tooltip.onMouseOut_ = function(_e) {
|
||||
if (Blockly.Tooltip.blocked_) {
|
||||
// Someone doesn't want us to show tooltips.
|
||||
return;
|
||||
|
|
|
@ -171,13 +171,20 @@ Blockly.Trashcan.prototype.createDom = function() {
|
|||
{'id': 'blocklyTrashBodyClipPath' + rnd},
|
||||
this.svgGroup_);
|
||||
Blockly.utils.createSvgElement('rect',
|
||||
{'width': this.WIDTH_, 'height': this.BODY_HEIGHT_,
|
||||
'y': this.LID_HEIGHT_},
|
||||
{
|
||||
'width': this.WIDTH_,
|
||||
'height': this.BODY_HEIGHT_,
|
||||
'y': this.LID_HEIGHT_
|
||||
},
|
||||
clip);
|
||||
var body = Blockly.utils.createSvgElement('image',
|
||||
{'width': Blockly.SPRITE.width, 'x': -this.SPRITE_LEFT_,
|
||||
'height': Blockly.SPRITE.height, 'y': -this.SPRITE_TOP_,
|
||||
'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')'},
|
||||
{
|
||||
'width': Blockly.SPRITE.width,
|
||||
'x': -this.SPRITE_LEFT_,
|
||||
'height': Blockly.SPRITE.height,
|
||||
'y': -this.SPRITE_TOP_,
|
||||
'clip-path': 'url(#blocklyTrashBodyClipPath' + rnd + ')'
|
||||
},
|
||||
this.svgGroup_);
|
||||
body.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||
this.workspace_.options.pathToMedia + Blockly.SPRITE.url);
|
||||
|
@ -188,9 +195,13 @@ Blockly.Trashcan.prototype.createDom = function() {
|
|||
Blockly.utils.createSvgElement('rect',
|
||||
{'width': this.WIDTH_, 'height': this.LID_HEIGHT_}, clip);
|
||||
this.svgLid_ = Blockly.utils.createSvgElement('image',
|
||||
{'width': Blockly.SPRITE.width, 'x': -this.SPRITE_LEFT_,
|
||||
'height': Blockly.SPRITE.height, 'y': -this.SPRITE_TOP_,
|
||||
'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')'},
|
||||
{
|
||||
'width': Blockly.SPRITE.width,
|
||||
'x': -this.SPRITE_LEFT_,
|
||||
'height': Blockly.SPRITE.height,
|
||||
'y': -this.SPRITE_TOP_,
|
||||
'clip-path': 'url(#blocklyTrashLidClipPath' + rnd + ')'
|
||||
},
|
||||
this.svgGroup_);
|
||||
this.svgLid_.setAttributeNS('http://www.w3.org/1999/xlink', 'xlink:href',
|
||||
this.workspace_.options.pathToMedia + Blockly.SPRITE.url);
|
||||
|
|
|
@ -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.
|
||||
|
|
|
@ -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() {
|
||||
|
@ -122,7 +122,7 @@ Blockly.utils.removeClass = function(element, className) {
|
|||
* @param {!Element} element DOM element to check.
|
||||
* @param {string} className Name of class to check.
|
||||
* @return {boolean} True if class exists, false otherwise.
|
||||
* @private
|
||||
* @package
|
||||
*/
|
||||
Blockly.utils.hasClass = function(element, className) {
|
||||
var classes = element.getAttribute('class');
|
||||
|
@ -325,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();
|
||||
|
@ -451,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] : '';
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -36,11 +36,11 @@ goog.require('Blockly.VariableModel');
|
|||
* @constructor
|
||||
*/
|
||||
Blockly.VariableMap = function(workspace) {
|
||||
/**
|
||||
/**
|
||||
* 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_ = {};
|
||||
|
@ -169,7 +169,7 @@ Blockly.VariableMap.prototype.renameVariableWithConflict_ = function(variable,
|
|||
* @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.
|
||||
*/
|
||||
|
@ -313,7 +313,7 @@ Blockly.VariableMap.prototype.getVariable = function(name, opt_type) {
|
|||
};
|
||||
|
||||
/**
|
||||
* 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.
|
||||
|
@ -335,7 +335,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) {
|
||||
|
@ -368,7 +368,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 = [];
|
||||
|
|
|
@ -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
|
||||
* each variable type.
|
||||
* @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_;
|
||||
|
|
|
@ -57,21 +57,27 @@ Blockly.Warning.prototype.collapseHidden = false;
|
|||
Blockly.Warning.prototype.drawIcon_ = function(group) {
|
||||
// Triangle with rounded corners.
|
||||
Blockly.utils.createSvgElement('path',
|
||||
{'class': 'blocklyIconShape',
|
||||
'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z'},
|
||||
group);
|
||||
{
|
||||
'class': 'blocklyIconShape',
|
||||
'd': 'M2,15Q-1,15 0.5,12L6.5,1.7Q8,-1 9.5,1.7L15.5,12Q17,15 14,15z'
|
||||
},
|
||||
group);
|
||||
// Can't use a real '!' text character since different browsers and operating
|
||||
// systems render it differently.
|
||||
// Body of exclamation point.
|
||||
Blockly.utils.createSvgElement('path',
|
||||
{'class': 'blocklyIconSymbol',
|
||||
'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z'},
|
||||
group);
|
||||
{
|
||||
'class': 'blocklyIconSymbol',
|
||||
'd': 'm7,4.8v3.16l0.27,2.27h1.46l0.27,-2.27v-3.16z'
|
||||
},
|
||||
group);
|
||||
// Dot of exclamation point.
|
||||
Blockly.utils.createSvgElement('rect',
|
||||
{'class': 'blocklyIconSymbol',
|
||||
'x': '7', 'y': '11', 'height': '2', 'width': '2'},
|
||||
group);
|
||||
{
|
||||
'class': 'blocklyIconSymbol',
|
||||
'x': '7', 'y': '11', 'height': '2', 'width': '2'
|
||||
},
|
||||
group);
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -81,11 +87,15 @@ Blockly.Warning.prototype.drawIcon_ = function(group) {
|
|||
* @private
|
||||
*/
|
||||
Blockly.Warning.textToDom_ = function(text) {
|
||||
var paragraph = /** @type {!SVGTextElement} */ (
|
||||
Blockly.utils.createSvgElement('text',
|
||||
{'class': 'blocklyText blocklyBubbleText',
|
||||
'y': Blockly.Bubble.BORDER_WIDTH},
|
||||
null));
|
||||
var paragraph = /** @type {!SVGTextElement} */
|
||||
(Blockly.utils.createSvgElement(
|
||||
'text',
|
||||
{
|
||||
'class': 'blocklyText blocklyBubbleText',
|
||||
'y': Blockly.Bubble.BORDER_WIDTH
|
||||
},
|
||||
null)
|
||||
);
|
||||
var lines = text.split('\n');
|
||||
for (var i = 0; i < lines.length; i++) {
|
||||
var tspanElement = Blockly.utils.createSvgElement('tspan',
|
||||
|
@ -136,10 +146,10 @@ Blockly.Warning.prototype.setVisible = function(visible) {
|
|||
|
||||
/**
|
||||
* Bring the warning to the top of the stack when clicked on.
|
||||
* @param {!Event} e Mouse up event.
|
||||
* @param {!Event} _e Mouse up event.
|
||||
* @private
|
||||
*/
|
||||
Blockly.Warning.prototype.bodyFocus_ = function(/*e*/) {
|
||||
Blockly.Warning.prototype.bodyFocus_ = function(_e) {
|
||||
this.bubble_.promote_();
|
||||
};
|
||||
|
||||
|
|
|
@ -200,7 +200,7 @@ Blockly.WidgetDiv.hideIfOwner = function(oldOwner) {
|
|||
* @param {boolean} rtl True if RTL, false if LTR.
|
||||
*/
|
||||
Blockly.WidgetDiv.position = function(anchorX, anchorY, windowSize,
|
||||
scrollOffset, rtl) {
|
||||
scrollOffset, rtl) {
|
||||
// Don't let the widget go above the top edge of the window.
|
||||
if (anchorY < scrollOffset.y) {
|
||||
anchorY = scrollOffset.y;
|
||||
|
|
|
@ -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) {
|
||||
|
@ -66,13 +66,13 @@ Blockly.Workspace = function(opt_options) {
|
|||
|
||||
/**
|
||||
* @type {!Array.<!Blockly.Events.Abstract>}
|
||||
* @private
|
||||
* @protected
|
||||
*/
|
||||
this.undoStack_ = [];
|
||||
|
||||
/**
|
||||
* @type {!Array.<!Blockly.Events.Abstract>}
|
||||
* @private
|
||||
* @protected
|
||||
*/
|
||||
this.redoStack_ = [];
|
||||
|
||||
|
@ -228,8 +228,8 @@ Blockly.Workspace.prototype.clear = function() {
|
|||
/* Begin functions that are just pass-throughs to the variable map. */
|
||||
/**
|
||||
* 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) {
|
||||
|
@ -237,13 +237,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
|
||||
* each variable type.
|
||||
* @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.
|
||||
*/
|
||||
|
@ -261,9 +261,9 @@ Blockly.Workspace.prototype.getVariableUsesById = function(id) {
|
|||
};
|
||||
|
||||
/**
|
||||
* 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) {
|
||||
this.variableMap_.deleteVariableById(id);
|
||||
|
@ -283,12 +283,13 @@ Blockly.Workspace.prototype.deleteVariableInternal_ = function(variable, uses) {
|
|||
/**
|
||||
* Check whether a variable exists with the given name. The check is
|
||||
* case-insensitive.
|
||||
* @param {string} name The name to check for.
|
||||
* @param {string} _name The name to check for.
|
||||
* @return {number} The index of the name in the variable list, or -1 if it is
|
||||
* not present.
|
||||
* @deprecated April 2017
|
||||
*/
|
||||
Blockly.Workspace.prototype.variableIndexOf = function(/* name */) {
|
||||
|
||||
Blockly.Workspace.prototype.variableIndexOf = function(_name) {
|
||||
console.warn(
|
||||
'Deprecated call to Blockly.Workspace.prototype.variableIndexOf');
|
||||
return -1;
|
||||
|
@ -308,10 +309,10 @@ Blockly.Workspace.prototype.getVariable = function(name, opt_type) {
|
|||
};
|
||||
|
||||
/**
|
||||
* 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);
|
||||
|
@ -362,7 +363,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) {
|
||||
|
@ -396,8 +397,7 @@ Blockly.Workspace.prototype.undo = function(redo) {
|
|||
for (var i = 0, event; event = events[i]; i++) {
|
||||
event.run(redo);
|
||||
}
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
Blockly.Events.recordUndo = true;
|
||||
}
|
||||
};
|
||||
|
|
|
@ -31,6 +31,7 @@ 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 +108,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
|
||||
|
|
|
@ -88,13 +88,14 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.createDom = function() {
|
|||
* <g class="blocklyBubbleCanvas">/g>
|
||||
* </svg>
|
||||
*/
|
||||
this.SVG_ = Blockly.utils.createSvgElement('svg', {
|
||||
'xmlns': Blockly.SVG_NS,
|
||||
'xmlns:html': Blockly.HTML_NS,
|
||||
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
||||
'version': '1.1',
|
||||
'class': 'blocklyWsDragSurface blocklyOverflowVisible'
|
||||
}, null);
|
||||
this.SVG_ = Blockly.utils.createSvgElement('svg',
|
||||
{
|
||||
'xmlns': Blockly.SVG_NS,
|
||||
'xmlns:html': Blockly.HTML_NS,
|
||||
'xmlns:xlink': 'http://www.w3.org/1999/xlink',
|
||||
'version': '1.1',
|
||||
'class': 'blocklyWsDragSurface blocklyOverflowVisible'
|
||||
}, null);
|
||||
this.container_.appendChild(this.SVG_);
|
||||
};
|
||||
|
||||
|
@ -110,12 +111,12 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.createDom = function() {
|
|||
Blockly.WorkspaceDragSurfaceSvg.prototype.translateSurface = function(x, y) {
|
||||
// This is a work-around to prevent a the blocks from rendering
|
||||
// fuzzy while they are being moved on the drag surface.
|
||||
x = x.toFixed(0);
|
||||
y = y.toFixed(0);
|
||||
var fixedX = x.toFixed(0);
|
||||
var fixedY = y.toFixed(0);
|
||||
|
||||
this.SVG_.style.display = 'block';
|
||||
Blockly.utils.setCssTransform(this.SVG_,
|
||||
'translate3d(' + x + 'px, ' + y + 'px, 0px)');
|
||||
Blockly.utils.setCssTransform(
|
||||
this.SVG_, 'translate3d(' + fixedX + 'px, ' + fixedY + 'px, 0px)');
|
||||
};
|
||||
|
||||
/**
|
||||
|
@ -131,11 +132,14 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.getSurfaceTranslation = function() {
|
|||
/**
|
||||
* Move the blockCanvas and bubbleCanvas out of the surface SVG and on to
|
||||
* newSurface.
|
||||
* @param {!SVGElement} newSurface The element to put the drag surface contents
|
||||
* @param {SVGElement} newSurface The element to put the drag surface contents
|
||||
* into.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
||||
if (!newSurface) {
|
||||
throw 'Couldn\'t clear and hide the drag surface: missing new surface.';
|
||||
}
|
||||
var blockCanvas = this.SVG_.childNodes[0];
|
||||
var bubbleCanvas = this.SVG_.childNodes[1];
|
||||
if (!blockCanvas || !bubbleCanvas ||
|
||||
|
@ -156,8 +160,8 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
|||
Blockly.utils.insertAfter_(bubbleCanvas, blockCanvas);
|
||||
// Hide the drag surface.
|
||||
this.SVG_.style.display = 'none';
|
||||
goog.asserts.assert(this.SVG_.childNodes.length == 0,
|
||||
'Drag surface was not cleared.');
|
||||
goog.asserts.assert(
|
||||
this.SVG_.childNodes.length == 0, 'Drag surface was not cleared.');
|
||||
Blockly.utils.setCssTransform(this.SVG_, '');
|
||||
this.previousSibling_ = null;
|
||||
};
|
||||
|
@ -168,21 +172,21 @@ Blockly.WorkspaceDragSurfaceSvg.prototype.clearAndHide = function(newSurface) {
|
|||
* @param {!Element} blockCanvas The block canvas <g> element from the workspace.
|
||||
* @param {!Element} bubbleCanvas The <g> element that contains the bubbles.
|
||||
* @param {?Element} previousSibling The element to insert the block canvas &
|
||||
bubble canvas after when it goes back in the dom at the end of a drag.
|
||||
* @param {number} width The width of the workspace svg element.
|
||||
* @param {number} height The height of the workspace svg element.
|
||||
bubble canvas after when it goes back in the DOM at the end of a drag.
|
||||
* @param {number} width The width of the workspace SVG element.
|
||||
* @param {number} height The height of the workspace SVG element.
|
||||
* @param {number} scale The scale of the workspace being dragged.
|
||||
* @package
|
||||
*/
|
||||
Blockly.WorkspaceDragSurfaceSvg.prototype.setContentsAndShow = function(
|
||||
blockCanvas, bubbleCanvas, previousSibling, width, height, scale) {
|
||||
goog.asserts.assert(this.SVG_.childNodes.length == 0,
|
||||
'Already dragging a block.');
|
||||
goog.asserts.assert(
|
||||
this.SVG_.childNodes.length == 0, 'Already dragging a block.');
|
||||
this.previousSibling_ = previousSibling;
|
||||
// Make sure the blocks and bubble canvas are scaled appropriately.
|
||||
blockCanvas.setAttribute('transform', 'translate(0, 0) scale(' + scale + ')');
|
||||
bubbleCanvas.setAttribute('transform',
|
||||
'translate(0, 0) scale(' + scale + ')');
|
||||
bubbleCanvas.setAttribute(
|
||||
'transform', 'translate(0, 0) scale(' + scale + ')');
|
||||
this.SVG_.setAttribute('width', width);
|
||||
this.SVG_.setAttribute('height', height);
|
||||
this.SVG_.appendChild(blockCanvas);
|
||||
|
|
|
@ -61,8 +61,8 @@ Blockly.WorkspaceDragger = function(workspace) {
|
|||
* @type {!goog.math.Coordinate}
|
||||
* @private
|
||||
*/
|
||||
this.startScrollXY_ = new goog.math.Coordinate(workspace.scrollX,
|
||||
workspace.scrollY);
|
||||
this.startScrollXY_ = new goog.math.Coordinate(
|
||||
workspace.scrollX, workspace.scrollY);
|
||||
};
|
||||
|
||||
/**
|
||||
|
|
|
@ -267,7 +267,7 @@ Blockly.WorkspaceSvg.prototype.injectionDiv_ = 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_ = {};
|
||||
|
@ -275,7 +275,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_ = {};
|
||||
|
@ -509,7 +509,7 @@ Blockly.WorkspaceSvg.prototype.dispose = function() {
|
|||
}
|
||||
if (!this.options.parentWorkspace) {
|
||||
// Top-most workspace. Dispose of the div that the
|
||||
// svg is injected into (i.e. injectionDiv).
|
||||
// SVG is injected into (i.e. injectionDiv).
|
||||
goog.dom.removeNode(this.getParentSvg().parentNode);
|
||||
}
|
||||
if (this.resizeHandlerWrapper_) {
|
||||
|
@ -561,7 +561,7 @@ Blockly.WorkspaceSvg.prototype.addZoomControls_ = function(bottom) {
|
|||
/**
|
||||
* Add a flyout element in an element with the given tag name.
|
||||
* @param {string} tagName What type of tag the flyout belongs in.
|
||||
* @return {!Element} The element containing the flyout dom.
|
||||
* @return {!Element} The element containing the flyout DOM.
|
||||
* @private
|
||||
*/
|
||||
Blockly.WorkspaceSvg.prototype.addFlyout_ = function(tagName) {
|
||||
|
@ -581,7 +581,7 @@ Blockly.WorkspaceSvg.prototype.addFlyout_ = function(tagName) {
|
|||
this.flyout_.autoClose = false;
|
||||
|
||||
// Return the element so that callers can place it in their desired
|
||||
// spot in the dom. For exmaple, mutator flyouts do not go in the same place
|
||||
// spot in the DOM. For example, mutator flyouts do not go in the same place
|
||||
// as main workspace flyouts.
|
||||
return this.flyout_.createDom(tagName);
|
||||
};
|
||||
|
@ -731,7 +731,7 @@ Blockly.WorkspaceSvg.prototype.translate = function(x, y) {
|
|||
|
||||
/**
|
||||
* Called at the end of a workspace drag to take the contents
|
||||
* out of the drag surface and put them back into the workspace svg.
|
||||
* out of the drag surface and put them back into the workspace SVG.
|
||||
* Does nothing if the workspace drag surface is not enabled.
|
||||
* @package
|
||||
*/
|
||||
|
@ -746,7 +746,7 @@ Blockly.WorkspaceSvg.prototype.resetDragSurface = function() {
|
|||
var trans = this.workspaceDragSurface_.getSurfaceTranslation();
|
||||
this.workspaceDragSurface_.clearAndHide(this.svgGroup_);
|
||||
var translation = 'translate(' + trans.x + ',' + trans.y + ') ' +
|
||||
'scale(' + this.scale + ')';
|
||||
'scale(' + this.scale + ')';
|
||||
this.svgBlockCanvas_.setAttribute('transform', translation);
|
||||
this.svgBubbleCanvas_.setAttribute('transform', translation);
|
||||
};
|
||||
|
@ -777,8 +777,8 @@ Blockly.WorkspaceSvg.prototype.setupDragSurface = function() {
|
|||
// Figure out where we want to put the canvas back. The order
|
||||
// in the is important because things are layered.
|
||||
var previousElement = this.svgBlockCanvas_.previousSibling;
|
||||
var width = this.getParentSvg().getAttribute("width");
|
||||
var height = this.getParentSvg().getAttribute("height");
|
||||
var width = parseInt(this.getParentSvg().getAttribute('width'), 10);
|
||||
var height = parseInt(this.getParentSvg().getAttribute('height'), 10);
|
||||
var coord = Blockly.utils.getRelativeXY(this.svgBlockCanvas_);
|
||||
this.workspaceDragSurface_.setContentsAndShow(this.svgBlockCanvas_,
|
||||
this.svgBubbleCanvas_, previousElement, width, height, this.scale);
|
||||
|
@ -1032,7 +1032,7 @@ Blockly.WorkspaceSvg.prototype.refreshToolboxSelection_ = function() {
|
|||
/**
|
||||
* 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
|
||||
*/
|
||||
|
@ -1044,7 +1044,7 @@ Blockly.WorkspaceSvg.prototype.renameVariableById = function(id, newName) {
|
|||
/**
|
||||
* 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) {
|
||||
|
@ -1059,7 +1059,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
|
||||
|
@ -1584,6 +1584,7 @@ Blockly.WorkspaceSvg.prototype.zoomToFit = function() {
|
|||
Blockly.WorkspaceSvg.prototype.scrollCenter = function() {
|
||||
if (!this.scrollbar) {
|
||||
// Can't center a non-scrolling workspace.
|
||||
console.warn('Tried to scroll a non-scrollable workspace.');
|
||||
return;
|
||||
}
|
||||
// Hide the WidgetDiv without animation (zoom makes field out of place with div)
|
||||
|
@ -1752,7 +1753,7 @@ Blockly.WorkspaceSvg.getContentDimensionsExact_ = function(ws) {
|
|||
Blockly.WorkspaceSvg.getContentDimensionsBounded_ = function(ws, svgSize) {
|
||||
var content = Blockly.WorkspaceSvg.getContentDimensionsExact_(ws);
|
||||
|
||||
// View height and width are both in pixels, and are the same as the svg size.
|
||||
// View height and width are both in pixels, and are the same as the SVG size.
|
||||
var viewWidth = svgSize.width;
|
||||
var viewHeight = svgSize.height;
|
||||
var halfWidth = viewWidth / 2;
|
||||
|
@ -1968,7 +1969,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,
|
||||
|
@ -1982,7 +1983,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.
|
||||
*/
|
||||
|
|
46
core/xml.js
46
core/xml.js
|
@ -38,7 +38,7 @@ goog.require('goog.userAgent');
|
|||
/**
|
||||
* 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) {
|
||||
|
@ -71,7 +71,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) {
|
||||
|
@ -165,7 +165,7 @@ Blockly.Xml.allFieldsToDom_ = function(block, element) {
|
|||
/**
|
||||
* 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) {
|
||||
|
@ -379,7 +379,7 @@ Blockly.Xml.clearWorkspaceAndLoadFromXml = function(xml, workspace) {
|
|||
* 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) {
|
||||
|
@ -393,7 +393,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
|
||||
|
@ -420,8 +420,10 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
|||
// to be moved to a nested destination in the next operation.
|
||||
var block = Blockly.Xml.domToBlock(xmlChild, workspace);
|
||||
newBlockIds.push(block.id);
|
||||
var blockX = parseInt(xmlChild.getAttribute('x'), 10);
|
||||
var blockY = parseInt(xmlChild.getAttribute('y'), 10);
|
||||
var blockX = xmlChild.hasAttribute('x') ?
|
||||
parseInt(xmlChild.getAttribute('x'), 10) : 10;
|
||||
var blockY = xmlChild.hasAttribute('y') ?
|
||||
parseInt(xmlChild.getAttribute('y'), 10) : 10;
|
||||
if (!isNaN(blockX) && !isNaN(blockY)) {
|
||||
block.moveBy(workspace.RTL ? width - blockX : blockX, blockY);
|
||||
}
|
||||
|
@ -429,11 +431,10 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
|||
} else if (name == 'shadow') {
|
||||
goog.asserts.fail('Shadow block cannot be a top-level block.');
|
||||
variablesFirst = false;
|
||||
} else if (name == 'variables') {
|
||||
} else if (name == 'variables') {
|
||||
if (variablesFirst) {
|
||||
Blockly.Xml.domToVariables(xmlChild, workspace);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
throw Error('\'variables\' tag must exist once before block and ' +
|
||||
'shadow tag elements in the workspace XML, but it was found in ' +
|
||||
'another location.');
|
||||
|
@ -441,8 +442,7 @@ Blockly.Xml.domToWorkspace = function(xml, workspace) {
|
|||
variablesFirst = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
finally {
|
||||
} finally {
|
||||
if (!existingGroup) {
|
||||
Blockly.Events.setGroup(false);
|
||||
}
|
||||
|
@ -460,12 +460,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 {
|
||||
|
@ -475,7 +475,7 @@ 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
|
||||
|
@ -566,7 +566,7 @@ Blockly.Xml.domToBlock = function(xmlBlock, workspace) {
|
|||
var newVariables = Blockly.Variables.getAddedVariables(workspace,
|
||||
variablesBeforeCreation);
|
||||
// Fire a VarCreate event for each (if any) new variable created.
|
||||
for(var i = 0; i < newVariables.length; i++) {
|
||||
for (var i = 0; i < newVariables.length; i++) {
|
||||
var thisVariable = newVariables[i];
|
||||
Blockly.Events.fire(new Blockly.Events.VarCreate(thisVariable));
|
||||
}
|
||||
|
@ -607,8 +607,8 @@ Blockly.Xml.domToVariables = function(xmlVariables, workspace) {
|
|||
Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
||||
var block = null;
|
||||
var prototypeName = xmlBlock.getAttribute('type');
|
||||
goog.asserts.assert(prototypeName, 'Block type unspecified: %s',
|
||||
xmlBlock.outerHTML);
|
||||
goog.asserts.assert(
|
||||
prototypeName, 'Block type unspecified: %s', xmlBlock.outerHTML);
|
||||
var id = xmlBlock.getAttribute('id');
|
||||
block = workspace.newBlock(prototypeName, id);
|
||||
|
||||
|
@ -731,7 +731,7 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
|||
}
|
||||
var disabled = xmlBlock.getAttribute('disabled');
|
||||
if (disabled) {
|
||||
block.setDisabled(disabled == 'true');
|
||||
block.setDisabled(disabled == 'true' || disabled == 'disabled');
|
||||
}
|
||||
var deletable = xmlBlock.getAttribute('deletable');
|
||||
if (deletable) {
|
||||
|
@ -753,8 +753,8 @@ Blockly.Xml.domToBlockHeadless_ = function(xmlBlock, workspace) {
|
|||
// Ensure all children are also shadows.
|
||||
var children = block.getChildren();
|
||||
for (var i = 0, child; child = children[i]; i++) {
|
||||
goog.asserts.assert(child.isShadow(),
|
||||
'Shadow block not allowed non-shadow child.');
|
||||
goog.asserts.assert(
|
||||
child.isShadow(), 'Shadow block not allowed non-shadow child.');
|
||||
}
|
||||
block.setShadow(true);
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue