More lint and small changes from Blockly

This commit is contained in:
Rachel Fenichel 2018-04-30 15:42:02 -07:00
parent f0b6e72888
commit 3c992dee6a
19 changed files with 174 additions and 123 deletions

View file

@ -51,7 +51,7 @@ goog.require('goog.string');
* @param {?string} prototypeName Name of the language object containing * @param {?string} prototypeName Name of the language object containing
* type-specific functions for this block. * type-specific functions for this block.
* @param {string=} opt_id Optional ID. Use this ID if provided, otherwise * @param {string=} opt_id Optional ID. Use this ID if provided, otherwise
* create a new id. * create a new ID.
* @constructor * @constructor
*/ */
Blockly.Block = function(workspace, prototypeName, opt_id) { Blockly.Block = function(workspace, prototypeName, opt_id) {
@ -1188,11 +1188,12 @@ Blockly.Block.prototype.appendDummyInput = function(opt_name) {
* @param {!Object} json Structured data describing the block. * @param {!Object} json Structured data describing the block.
*/ */
Blockly.Block.prototype.jsonInit = function(json) { Blockly.Block.prototype.jsonInit = function(json) {
var warningPrefix = json['type'] ? 'Block "' + json['type'] + '": ' : '';
// Validate inputs. // Validate inputs.
goog.asserts.assert(json['output'] == undefined || goog.asserts.assert(
json['previousStatement'] == undefined, json['output'] == undefined || json['previousStatement'] == undefined,
'Must not have both an output and a previousStatement.'); warningPrefix + 'Must not have both an output and a previousStatement.');
// Set basic properties of block. // Set basic properties of block.
if (json['colour'] !== undefined) { if (json['colour'] !== undefined) {
@ -1343,11 +1344,11 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
var token = tokens[i]; var token = tokens[i];
if (typeof token == 'number') { if (typeof token == 'number') {
if (token <= 0 || token > args.length) { if (token <= 0 || token > args.length) {
throw new Error('Block \"' + this.type + '\": ' + throw new Error('Block "' + this.type + '": ' +
'Message index %' + token + ' out of range.'); 'Message index %' + token + ' out of range.');
} }
if (indexDup[token]) { if (indexDup[token]) {
throw new Error('Block \"' + this.type + '\": ' + throw new Error('Block "' + this.type + '": ' +
'Message index %' + token + ' duplicated.'); 'Message index %' + token + ' duplicated.');
} }
indexDup[token] = true; indexDup[token] = true;
@ -1360,14 +1361,14 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) {
} }
} }
} }
if(indexCount != args.length) { if (indexCount != args.length) {
throw new Error('Block \"' + this.type + '\": ' + throw new Error('Block "' + this.type + '": ' +
'Message does not reference all ' + args.length + ' arg(s).'); 'Message does not reference all ' + args.length + ' arg(s).');
} }
// Add last dummy input if needed. // Add last dummy input if needed.
if (elements.length && (typeof elements[elements.length - 1] == 'string' || if (elements.length && (typeof elements[elements.length - 1] == 'string' ||
goog.string.startsWith(elements[elements.length - 1]['type'], goog.string.startsWith(
'field_'))) { elements[elements.length - 1]['type'], 'field_'))) {
var dummyInput = {type: 'input_dummy'}; var dummyInput = {type: 'input_dummy'};
if (lastDummyAlign) { if (lastDummyAlign) {
dummyInput['align'] = lastDummyAlign; dummyInput['align'] = lastDummyAlign;
@ -1487,8 +1488,8 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) {
} }
} }
goog.asserts.assert(inputIndex != -1, 'Named input "%s" not found.', name); goog.asserts.assert(inputIndex != -1, 'Named input "%s" not found.', name);
goog.asserts.assert(refIndex != -1, 'Reference input "%s" not found.', goog.asserts.assert(
refName); refIndex != -1, 'Reference input "%s" not found.', refName);
this.moveNumberedInputBefore(inputIndex, refIndex); this.moveNumberedInputBefore(inputIndex, refIndex);
}; };
@ -1502,9 +1503,9 @@ Blockly.Block.prototype.moveNumberedInputBefore = function(
// Validate arguments. // Validate arguments.
goog.asserts.assert(inputIndex != refIndex, 'Can\'t move input to itself.'); goog.asserts.assert(inputIndex != refIndex, 'Can\'t move input to itself.');
goog.asserts.assert(inputIndex < this.inputList.length, goog.asserts.assert(inputIndex < this.inputList.length,
'Input index ' + inputIndex + ' out of bounds.'); 'Input index ' + inputIndex + ' out of bounds.');
goog.asserts.assert(refIndex <= this.inputList.length, goog.asserts.assert(refIndex <= this.inputList.length,
'Reference input ' + refIndex + ' out of bounds.'); 'Reference input ' + refIndex + ' out of bounds.');
// Remove input. // Remove input.
var input = this.inputList[inputIndex]; var input = this.inputList[inputIndex];
this.inputList.splice(inputIndex, 1); this.inputList.splice(inputIndex, 1);

View file

@ -36,7 +36,7 @@ goog.require('goog.asserts');
/** /**
* Class for a block dragger. It moves blocks around the workspace when they * Class for a block dragger. It moves blocks around the workspace when they
* are being dragged by a mouse or touch. * are being dragged by a mouse or touch.
* @param {!Blockly.Block} block The block to drag. * @param {!Blockly.BlockSvg} block The block to drag.
* @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on. * @param {!Blockly.WorkspaceSvg} workspace The workspace to drag on.
* @constructor * @constructor
*/ */

View file

@ -1037,7 +1037,7 @@ Blockly.BlockSvg.prototype.setWarningText = function(text, opt_id) {
} }
this.warning.setText(/** @type {string} */ (text), id); this.warning.setText(/** @type {string} */ (text), id);
} else { } else {
// Dispose all warnings if no id is given. // Dispose all warnings if no ID is given.
if (this.warning && !id) { if (this.warning && !id) {
this.warning.dispose(); this.warning.dispose();
changedState = true; changedState = true;
@ -1113,11 +1113,11 @@ Blockly.BlockSvg.prototype.setMouseThroughStyle = function(letMouseThrough) {
*/ */
Blockly.BlockSvg.prototype.setDeleteStyle = function(enable) { Blockly.BlockSvg.prototype.setDeleteStyle = function(enable) {
if (enable) { if (enable) {
Blockly.utils.addClass( Blockly.utils.addClass(/** @type {!Element} */ (this.svgGroup_),
/** @type {!Element} */ (this.svgGroup_), 'blocklyDraggingDelete'); 'blocklyDraggingDelete');
} else { } else {
Blockly.utils.removeClass( Blockly.utils.removeClass(/** @type {!Element} */ (this.svgGroup_),
/** @type {!Element} */ (this.svgGroup_), 'blocklyDraggingDelete'); 'blocklyDraggingDelete');
} }
}; };
@ -1164,9 +1164,8 @@ Blockly.BlockSvg.prototype.bringToFront = function() {
* @param {(string|Array.<string>|null)=} opt_check Statement type or * @param {(string|Array.<string>|null)=} opt_check Statement type or
* list of statement types. Null/undefined if any type could be connected. * list of statement types. Null/undefined if any type could be connected.
*/ */
Blockly.BlockSvg.prototype.setPreviousStatement = Blockly.BlockSvg.prototype.setPreviousStatement = function(newBoolean,
function(newBoolean, opt_check) { opt_check) {
/* eslint-disable indent */
Blockly.BlockSvg.superClass_.setPreviousStatement.call(this, newBoolean, Blockly.BlockSvg.superClass_.setPreviousStatement.call(this, newBoolean,
opt_check); opt_check);
@ -1174,7 +1173,7 @@ Blockly.BlockSvg.prototype.setPreviousStatement =
this.render(); this.render();
this.bumpNeighbours_(); this.bumpNeighbours_();
} }
}; /* eslint-enable indent */ };
/** /**
* Set whether another block can chain onto the bottom of this block. * Set whether another block can chain onto the bottom of this block.

View file

@ -126,8 +126,10 @@ Blockly.hueToRgb = function(hue) {
* @return {!Object} Contains width and height properties. * @return {!Object} Contains width and height properties.
*/ */
Blockly.svgSize = function(svg) { Blockly.svgSize = function(svg) {
return {width: svg.cachedWidth_, return {
height: svg.cachedHeight_}; width: svg.cachedWidth_,
height: svg.cachedHeight_
};
}; };
/** /**
@ -324,7 +326,6 @@ Blockly.confirm = function(message, callback) {
callback(window.confirm(message)); callback(window.confirm(message));
}; };
/* eslint-disable no-unused-vars */
/** /**
* Wrapper to window.prompt() that app developers may override to provide * Wrapper to window.prompt() that app developers may override to provide
* alternatives to the modal browser window. Built-in browser prompts are * alternatives to the modal browser window. Built-in browser prompts are
@ -333,17 +334,16 @@ Blockly.confirm = function(message, callback) {
* @param {string} message The message to display to the user. * @param {string} message The message to display to the user.
* @param {string} defaultValue The value to initialize the prompt with. * @param {string} defaultValue The value to initialize the prompt with.
* @param {!function(string)} callback The callback for handling user response. * @param {!function(string)} callback The callback for handling user response.
* @param {?string} opt_title An optional title for the prompt. * @param {?string} _opt_title An optional title for the prompt.
* @param {?string} opt_varType An optional variable type for variable specific * @param {?string} _opt_varType An optional variable type for variable specific
* prompt behavior. * prompt behavior.
*/ */
Blockly.prompt = function(message, defaultValue, callback, opt_title, Blockly.prompt = function(message, defaultValue, callback, _opt_title,
opt_varType) { _opt_varType) {
// opt_title and opt_varType are unused because we only need them to pass // opt_title and opt_varType are unused because we only need them to pass
// information to the scratch-gui, which overwrites this function // information to the scratch-gui, which overwrites this function
callback(window.prompt(message, defaultValue)); callback(window.prompt(message, defaultValue));
}; };
/* eslint-enable no-unused-vars */
/** /**
* Helper function for defining a block from JSON. The resulting function has * Helper function for defining a block from JSON. The resulting function has
@ -365,19 +365,28 @@ Blockly.jsonInitFactory_ = function(jsonDef) {
* @param {!Array.<!Object>} jsonArray An array of JSON block definitions. * @param {!Array.<!Object>} jsonArray An array of JSON block definitions.
*/ */
Blockly.defineBlocksWithJsonArray = function(jsonArray) { Blockly.defineBlocksWithJsonArray = function(jsonArray) {
for (var i = 0, elem; elem = jsonArray[i]; i++) { for (var i = 0; i < jsonArray.length; i++) {
var typename = elem.type; var elem = jsonArray[i];
if (typename == null || typename === '') { if (!elem) {
console.warn('Block definition #' + i + console.warn(
' in JSON array is missing a type attribute. Skipping.'); 'Block definition #' + i + ' in JSON array is ' + elem + '. ' +
'Skipping.');
} else { } else {
if (Blockly.Blocks[typename]) { var typename = elem.type;
console.warn('Block definition #' + i + if (typename == null || typename === '') {
' in JSON array overwrites prior definition of "' + typename + '".'); console.warn(
'Block definition #' + i +
' in JSON array is missing a type attribute. Skipping.');
} else {
if (Blockly.Blocks[typename]) {
console.warn(
'Block definition #' + i + ' in JSON array' +
' overwrites prior definition of "' + typename + '".');
}
Blockly.Blocks[typename] = {
init: Blockly.jsonInitFactory_(elem)
};
} }
Blockly.Blocks[typename] = {
init: Blockly.jsonInitFactory_(elem)
};
} }
} }
}; };

View file

@ -162,7 +162,7 @@ Blockly.Bubble.bubbleMouseUp_ = function(/*e*/) {
Blockly.Bubble.prototype.rendered_ = false; Blockly.Bubble.prototype.rendered_ = false;
/** /**
* Absolute coordinate of anchor point, in workspace coordinates * Absolute coordinate of anchor point, in workspace coordinates.
* @type {goog.math.Coordinate} * @type {goog.math.Coordinate}
* @private * @private
*/ */
@ -256,10 +256,8 @@ Blockly.Bubble.prototype.createDom_ = function(content, hasResize) {
Blockly.utils.createSvgElement('line', Blockly.utils.createSvgElement('line',
{ {
'class': 'blocklyResizeLine', 'class': 'blocklyResizeLine',
'x1': resizeSize / 3, 'x1': resizeSize / 3, 'y1': resizeSize - 1,
'y1': resizeSize - 1, 'x2': resizeSize - 1, 'y2': resizeSize / 3
'x2': resizeSize - 1,
'y2': resizeSize / 3
}, this.resizeGroup_); }, this.resizeGroup_);
Blockly.utils.createSvgElement('line', Blockly.utils.createSvgElement('line',
{ {
@ -371,11 +369,16 @@ Blockly.Bubble.prototype.registerResizeEvent = function(callback) {
/** /**
* Move this bubble to the top of the stack. * Move this bubble to the top of the stack.
* @return {!boolean} Whether or not the bubble has been moved.
* @private * @private
*/ */
Blockly.Bubble.prototype.promote_ = function() { Blockly.Bubble.prototype.promote_ = function() {
var svgGroup = this.bubbleGroup_.parentNode; var svgGroup = this.bubbleGroup_.parentNode;
svgGroup.appendChild(this.bubbleGroup_); if (svgGroup.lastChild !== this.bubbleGroup_) {
svgGroup.appendChild(this.bubbleGroup_);
return true;
}
return false;
}; };
/** /**
@ -448,8 +451,17 @@ Blockly.Bubble.prototype.positionBubble_ = function() {
left += this.relativeLeft_; left += this.relativeLeft_;
} }
var top = this.relativeTop_ + this.anchorXY_.y; var top = this.relativeTop_ + this.anchorXY_.y;
this.bubbleGroup_.setAttribute('transform', this.moveTo(left, top);
'translate(' + left + ',' + top + ')'); };
/**
* Move the bubble group to the specified location in workspace coordinates.
* @param {number} x The x position to move to.
* @param {number} y The y position to move to.
* @package
*/
Blockly.Bubble.prototype.moveTo = function(x, y) {
this.bubbleGroup_.setAttribute('transform', 'translate(' + x + ',' + y + ')');
}; };
/** /**

View file

@ -126,10 +126,10 @@ Blockly.Comment.prototype.createEditor_ = function() {
Blockly.bindEventWithChecks_(textarea, 'wheel', this, function(e) { Blockly.bindEventWithChecks_(textarea, 'wheel', this, function(e) {
e.stopPropagation(); e.stopPropagation();
}); });
Blockly.bindEventWithChecks_(textarea, 'change', this, function(/* e */) { Blockly.bindEventWithChecks_(textarea, 'change', this, function(_e) {
if (this.text_ != textarea.value) { if (this.text_ != textarea.value) {
Blockly.Events.fire(new Blockly.Events.BlockChange( Blockly.Events.fire(new Blockly.Events.BlockChange(
this.block_, 'comment', null, this.text_, textarea.value)); this.block_, 'comment', null, this.text_, textarea.value));
this.text_ = textarea.value; this.text_ = textarea.value;
} }
}); });
@ -213,17 +213,18 @@ Blockly.Comment.prototype.setVisible = function(visible) {
/** /**
* Bring the comment to the top of the stack when clicked on. * Bring the comment to the top of the stack when clicked on.
* @param {!Event} e Mouse up event. * @param {!Event} _e Mouse up event.
* @private * @private
*/ */
Blockly.Comment.prototype.textareaFocus_ = function(/*e*/) { Blockly.Comment.prototype.textareaFocus_ = function(_e) {
// Ideally this would be hooked to the focus event for the comment. // Ideally this would be hooked to the focus event for the comment.
// However doing so in Firefox swallows the cursor for unknown reasons. // However doing so in Firefox swallows the cursor for unknown reasons.
// So this is hooked to mouseup instead. No big deal. // So this is hooked to mouseup instead. No big deal.
this.bubble_.promote_(); if (this.bubble_.promote_()) {
// Since the act of moving this node within the DOM causes a loss of focus, // Since the act of moving this node within the DOM causes a loss of focus,
// we need to reapply the focus. // we need to reapply the focus.
this.textarea_.focus(); this.textarea_.focus();
}
}; };
/** /**

View file

@ -76,6 +76,9 @@ Blockly.Extensions.register = function(name, initFn) {
* registered. * registered.
*/ */
Blockly.Extensions.registerMixin = function(name, mixinObj) { Blockly.Extensions.registerMixin = function(name, mixinObj) {
if (!goog.isObject(mixinObj)){
throw new Error('Error: Mixin "' + name + '" must be a object');
}
Blockly.Extensions.register(name, function() { Blockly.Extensions.register(name, function() {
this.mixin(mixinObj); this.mixin(mixinObj);
}); });
@ -373,24 +376,24 @@ Blockly.Extensions.buildTooltipForDropdown = function(dropdownName,
* Emits console warnings when they are not. * Emits console warnings when they are not.
* @param {!Blockly.Block} block The block containing the dropdown * @param {!Blockly.Block} block The block containing the dropdown
* @param {string} dropdownName The name of 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 * @private
*/ */
Blockly.Extensions.checkDropdownOptionsInTable_ = Blockly.Extensions.checkDropdownOptionsInTable_ = function(block, dropdownName,
function(block, dropdownName, lookupTable) { lookupTable) {
// Validate all dropdown options have values. // Validate all dropdown options have values.
var dropdown = block.getField(dropdownName); var dropdown = block.getField(dropdownName);
if (!dropdown.isOptionListDynamic()) { if (!dropdown.isOptionListDynamic()) {
var options = dropdown.getOptions(); var options = dropdown.getOptions();
for (var i = 0; i < options.length; ++i) { for (var i = 0; i < options.length; ++i) {
var optionKey = options[i][1]; // label, then value var optionKey = options[i][1]; // label, then value
if (lookupTable[optionKey] == null) { if (lookupTable[optionKey] == null) {
console.warn('No tooltip mapping for value ' + optionKey + console.warn('No tooltip mapping for value ' + optionKey +
' of field ' + dropdownName + ' of block type ' + block.type); ' of field ' + dropdownName + ' of block type ' + block.type);
}
} }
} }
}; }
};
/** /**
* Builds an extension function that will install a dynamic tooltip. The * Builds an extension function that will install a dynamic tooltip. The

View file

@ -733,14 +733,13 @@ Blockly.Field.prototype.onMouseDown_ = function(e) {
} }
}; };
/** /**
* Change the tooltip text for this field. * Change the tooltip text for this field.
* @param {string|!Element} newTip Text for tooltip or a parent element to * @param {string|!Element} _newTip Text for tooltip or a parent element to
* link to for its tooltip. * link to for its tooltip.
* @abstract * @abstract
*/ */
Blockly.Field.prototype.setTooltip = function(/*newTip*/) { Blockly.Field.prototype.setTooltip = function(_newTip) {
// Non-abstract sub-classes may wish to implement this. See FieldLabel. // Non-abstract sub-classes may wish to implement this. See FieldLabel.
}; };

View file

@ -34,6 +34,7 @@ goog.require('goog.events');
goog.require('goog.style'); goog.require('goog.style');
goog.require('goog.ui.ColorPicker'); goog.require('goog.ui.ColorPicker');
/** /**
* Class for a colour input field. * Class for a colour input field.
* @param {string} colour The initial colour in '#rrggbb' format. * @param {string} colour The initial colour in '#rrggbb' format.

View file

@ -30,6 +30,7 @@ goog.require('Blockly.Field');
goog.require('Blockly.utils'); goog.require('Blockly.utils');
goog.require('goog.date'); goog.require('goog.date');
goog.require('goog.date.DateTime');
goog.require('goog.dom'); goog.require('goog.dom');
goog.require('goog.events'); goog.require('goog.events');
goog.require('goog.i18n.DateTimeSymbols'); goog.require('goog.i18n.DateTimeSymbols');
@ -156,7 +157,7 @@ Blockly.FieldDate.prototype.createWidget_ = function() {
picker.setShowWeekNum(false); picker.setShowWeekNum(false);
var div = Blockly.WidgetDiv.DIV; var div = Blockly.WidgetDiv.DIV;
picker.render(div); picker.render(div);
picker.setDate(goog.date.fromIsoString(this.getValue())); picker.setDate(goog.date.DateTime.fromIsoString(this.getValue()));
return picker; return picker;
}; };

View file

@ -367,7 +367,8 @@ Blockly.FieldDropdown.prototype.trimOptions_ = function() {
}; };
/** /**
* @return {boolean} True if the option list is generated by a function. Otherwise false. * @return {boolean} True if the option list is generated by a function.
* Otherwise false.
*/ */
Blockly.FieldDropdown.prototype.isOptionListDynamic = function() { Blockly.FieldDropdown.prototype.isOptionListDynamic = function() {
return goog.isFunction(this.menuGenerator_); return goog.isFunction(this.menuGenerator_);

View file

@ -95,12 +95,12 @@ Blockly.FieldImage.prototype.init = function() {
} }
/** @type {SVGElement} */ /** @type {SVGElement} */
this.imageElement_ = Blockly.utils.createSvgElement( this.imageElement_ = Blockly.utils.createSvgElement(
'image', 'image',
{ {
'height': this.height_ + 'px', 'height': this.height_ + 'px',
'width': this.width_ + 'px' 'width': this.width_ + 'px'
}, },
this.fieldGroup_); this.fieldGroup_);
this.setValue(this.src_); this.setValue(this.src_);
this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_); this.sourceBlock_.getSvgRoot().appendChild(this.fieldGroup_);

View file

@ -359,11 +359,10 @@ Blockly.FieldVariable.prototype.onItemSelected = function(menu, menuItem) {
}; };
/** /**
* Whether this field references any Blockly variables. If true it may need to * Overrides referencesVariables(), indicating this field refers to a variable.
* be handled differently during serialization and deserialization. Subclasses * @return {boolean} True.
* may override this.
* @return {boolean} True if this field has any variable references.
* @package * @package
* @override
*/ */
Blockly.FieldVariable.prototype.referencesVariables = function() { Blockly.FieldVariable.prototype.referencesVariables = function() {
return true; return true;

View file

@ -50,7 +50,7 @@ Blockly.Flyout = function(workspaceOptions) {
/** /**
* @type {!Blockly.Workspace} * @type {!Blockly.Workspace}
* @private * @protected
*/ */
this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions); this.workspace_ = new Blockly.WorkspaceSvg(workspaceOptions);
this.workspace_.isFlyout = true; this.workspace_.isFlyout = true;
@ -352,7 +352,7 @@ Blockly.Flyout.prototype.getHeight = function() {
}; };
/** /**
* Get the flyout's workspace. * Get the workspace inside the flyout.
* @return {!Blockly.WorkspaceSvg} The workspace inside the flyout. * @return {!Blockly.WorkspaceSvg} The workspace inside the flyout.
* @package * @package
*/ */
@ -724,7 +724,7 @@ Blockly.Flyout.prototype.createBlock = function(originalBlock) {
Blockly.Events.setGroup(true); Blockly.Events.setGroup(true);
Blockly.Events.fire(new Blockly.Events.Create(newBlock)); Blockly.Events.fire(new Blockly.Events.Create(newBlock));
// Fire a VarCreate event for each (if any) new variable created. // 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]; var thisVariable = newVariables[i];
Blockly.Events.fire(new Blockly.Events.VarCreate(thisVariable)); Blockly.Events.fire(new Blockly.Events.VarCreate(thisVariable));
} }

View file

@ -145,20 +145,31 @@ Blockly.FlyoutButton.prototype.createDom = function() {
if (!this.isLabel_) { if (!this.isLabel_) {
// Shadow rectangle (light source does not mirror in RTL). // Shadow rectangle (light source does not mirror in RTL).
var shadow = Blockly.utils.createSvgElement('rect', var shadow = Blockly.utils.createSvgElement('rect',
{'class': 'blocklyFlyoutButtonShadow', {
'rx': 4, 'ry': 4, 'x': 1, 'y': 1}, 'class': 'blocklyFlyoutButtonShadow',
this.svgGroup_); 'rx': 4,
'ry': 4,
'x': 1,
'y': 1
},
this.svgGroup_);
} }
// Background rectangle. // Background rectangle.
var rect = Blockly.utils.createSvgElement('rect', var rect = Blockly.utils.createSvgElement('rect',
{'class': this.isLabel_ ? {
'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground', 'class': this.isLabel_ ?
'rx': 4, 'ry': 4}, 'blocklyFlyoutLabelBackground' : 'blocklyFlyoutButtonBackground',
'rx': 4, 'ry': 4
},
this.svgGroup_); this.svgGroup_);
var svgText = Blockly.utils.createSvgElement('text', var svgText = Blockly.utils.createSvgElement('text',
{'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText', {
'x': 0, 'y': 0, 'text-anchor': 'middle'}, 'class': this.isLabel_ ? 'blocklyFlyoutLabelText' : 'blocklyText',
'x': 0,
'y': 0,
'text-anchor': 'middle'
},
this.svgGroup_); this.svgGroup_);
svgText.textContent = this.text_; svgText.textContent = this.text_;

View file

@ -65,25 +65,37 @@ Blockly.Mutator.prototype.workspaceHeight_ = 0;
Blockly.Mutator.prototype.drawIcon_ = function(group) { Blockly.Mutator.prototype.drawIcon_ = function(group) {
// Square with rounded corners. // Square with rounded corners.
Blockly.utils.createSvgElement('rect', Blockly.utils.createSvgElement('rect',
{'class': 'blocklyIconShape', {
'rx': '4', 'ry': '4', 'class': 'blocklyIconShape',
'height': '16', 'width': '16'}, 'rx': '4',
group); 'ry': '4',
'height': '16',
'width': '16'
},
group);
// Gear teeth. // Gear teeth.
Blockly.utils.createSvgElement('path', Blockly.utils.createSvgElement('path',
{'class': 'blocklyIconSymbol', {
'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 ' + 'class': 'blocklyIconSymbol',
'0.41,0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 ' + 'd': 'm4.203,7.296 0,1.368 -0.92,0.677 -0.11,0.41 0.9,1.559 0.41,' +
'1.8,0 0.3,-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 ' + '0.11 1.043,-0.457 1.187,0.683 0.127,1.134 0.3,0.3 1.8,0 0.3,' +
'0.9,-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,-0.41 ' + '-0.299 0.127,-1.138 1.185,-0.682 1.046,0.458 0.409,-0.11 0.9,' +
'-0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 -0.127,-1.138 ' + '-1.559 -0.11,-0.41 -0.92,-0.677 0,-1.366 0.92,-0.677 0.11,' +
'-0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,0.682 -1.043,-0.457 ' + '-0.41 -0.9,-1.559 -0.409,-0.109 -1.046,0.458 -1.185,-0.682 ' +
'-0.41,0.11 -0.899,1.559 0.108,0.409z'}, '-0.127,-1.138 -0.3,-0.299 -1.8,0 -0.3,0.3 -0.126,1.135 -1.187,' +
group); '0.682 -1.043,-0.457 -0.41,0.11 -0.899,1.559 0.108,0.409z'
},
group);
// Axle hole. // Axle hole.
Blockly.utils.createSvgElement('circle', Blockly.utils.createSvgElement(
{'class': 'blocklyIconShape', 'r': '2.7', 'cx': '8', 'cy': '8'}, 'circle',
group); {
'class': 'blocklyIconShape',
'r': '2.7',
'cx': '8',
'cy': '8'
},
group);
}; };
/** /**

View file

@ -258,8 +258,8 @@ Blockly.Scrollbar.prototype.origin_ = new goog.math.Coordinate(0, 0);
Blockly.Scrollbar.prototype.originHasChanged_ = true; Blockly.Scrollbar.prototype.originHasChanged_ = true;
/** /**
* The size of the area within which the scrollbar handle can move. * The size of the area within which the scrollbar handle can move, in CSS
* Coordinate system: pixel coordinates. * pixels.
* @type {number} * @type {number}
* @private * @private
*/ */

View file

@ -34,6 +34,7 @@ goog.require('goog.events');
goog.require('goog.events.BrowserFeature'); goog.require('goog.events.BrowserFeature');
goog.require('goog.string'); goog.require('goog.string');
/** /**
* Which touch events are we currently paying attention to? * Which touch events are we currently paying attention to?
* @type {DOMString} * @type {DOMString}
@ -63,7 +64,7 @@ Blockly.longPid_ = 0;
/** /**
* Context menus on touch devices are activated using a long-press. * 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, * 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 * which after about a second opens the context menu. The tasks is killed
* if the touch event terminates early. * if the touch event terminates early.
@ -153,7 +154,7 @@ Blockly.Touch.getTouchIdentifierFromEvent = function(e) {
Blockly.Touch.checkTouchIdentifier = function(e) { Blockly.Touch.checkTouchIdentifier = function(e) {
var identifier = Blockly.Touch.getTouchIdentifierFromEvent(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. // identifiers may be zero.
if (Blockly.Touch.touchIdentifier_ != undefined && if (Blockly.Touch.touchIdentifier_ != undefined &&
Blockly.Touch.touchIdentifier_ != null) { Blockly.Touch.touchIdentifier_ != null) {

View file

@ -269,7 +269,7 @@ Blockly.utils.getScale_REGEXP_ = /scale\(\s*([-+\d.e]+)\s*\)/;
* @private * @private
*/ */
Blockly.utils.getRelativeXY.XY_3D_REGEX_ = Blockly.utils.getRelativeXY.XY_3D_REGEX_ =
/transform:\s*translate3d\(\s*([-+\d.e]+)px([ ,]\s*([-+\d.e]+)\s*)px([ ,]\s*([-+\d.e]+)\s*)px\)?/; /transform:\s*translate3d\(\s*([-+\d.e]+)px([ ,]\s*([-+\d.e]+)\s*)px([ ,]\s*([-+\d.e]+)\s*)px\)?/;
/** /**
* Static regex to pull the x,y,z values out of a translate3d() style property. * Static regex to pull the x,y,z values out of a translate3d() style property.
@ -278,7 +278,7 @@ Blockly.utils.getRelativeXY.XY_3D_REGEX_ =
* @private * @private
*/ */
Blockly.utils.getRelativeXY.XY_2D_REGEX_ = Blockly.utils.getRelativeXY.XY_2D_REGEX_ =
/transform:\s*translate\(\s*([-+\d.e]+)px([ ,]\s*([-+\d.e]+)\s*)px\)?/; /transform:\s*translate\(\s*([-+\d.e]+)px([ ,]\s*([-+\d.e]+)\s*)px\)?/;
/** /**
* Helper method for creating SVG elements. * Helper method for creating SVG elements.
@ -491,7 +491,8 @@ Blockly.utils.checkMessageReferences = function(message) {
* @return {!Array.<string|number>} Array of strings and numbers. * @return {!Array.<string|number>} Array of strings and numbers.
* @private * @private
*/ */
Blockly.utils.tokenizeInterpolation_ = function(message, parseInterpolationTokens) { Blockly.utils.tokenizeInterpolation_ = function(message,
parseInterpolationTokens) {
var tokens = []; var tokens = [];
var chars = message.split(''); var chars = message.split('');
chars.push(''); // End marker. chars.push(''); // End marker.
@ -499,7 +500,7 @@ Blockly.utils.tokenizeInterpolation_ = function(message, parseInterpolationToken
// 0 - Base case. // 0 - Base case.
// 1 - % found. // 1 - % found.
// 2 - Digit found. // 2 - Digit found.
// 3 - Message ref found // 3 - Message ref found.
var state = 0; var state = 0;
var buffer = []; var buffer = [];
var number = null; var number = null;