diff --git a/.eslintrc b/.eslintrc index 50a1eff62..ff27be4e0 100644 --- a/.eslintrc +++ b/.eslintrc @@ -3,7 +3,7 @@ "curly": ["error", "multi-line"], "eol-last": ["error"], "indent": [ - "warn", 2, # Blockly/Google use 2-space indents + "error", 2, # Blockly/Google use 2-space indents # Blockly/Google uses +4 space indents for line continuations. { "SwitchCase": 1, diff --git a/core/block.js b/core/block.js index f6727ab97..20384f870 100644 --- a/core/block.js +++ b/core/block.js @@ -1048,8 +1048,8 @@ Blockly.Block.prototype.appendDummyInput = function(opt_name) { Blockly.Block.prototype.jsonInit = function(json) { // Validate inputs. - goog.asserts.assert(json['output'] == undefined || - json['previousStatement'] == undefined, + goog.asserts.assert( + json['output'] == undefined || json['previousStatement'] == undefined, 'Must not have both an output and a previousStatement.'); // Set basic properties of block. @@ -1185,8 +1185,8 @@ Blockly.Block.prototype.interpolate_ = function(message, args, lastDummyAlign) { } // Add last dummy input if needed. if (elements.length && (typeof elements[elements.length - 1] == 'string' || - goog.string.startsWith(elements[elements.length - 1]['type'], - 'field_'))) { + goog.string.startsWith( + elements[elements.length - 1]['type'], 'field_'))) { var dummyInput = {type: 'input_dummy'}; if (lastDummyAlign) { dummyInput['align'] = lastDummyAlign; @@ -1392,8 +1392,8 @@ Blockly.Block.prototype.moveInputBefore = function(name, refName) { } } goog.asserts.assert(inputIndex != -1, 'Named input "%s" not found.', name); - goog.asserts.assert(refIndex != -1, 'Reference input "%s" not found.', - refName); + goog.asserts.assert( + refIndex != -1, 'Reference input "%s" not found.', refName); this.moveNumberedInputBefore(inputIndex, refIndex); }; @@ -1407,9 +1407,9 @@ Blockly.Block.prototype.moveNumberedInputBefore = function( // Validate arguments. goog.asserts.assert(inputIndex != refIndex, 'Can\'t move input to itself.'); 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, - 'Reference input ' + refIndex + ' out of bounds.'); + 'Reference input ' + refIndex + ' out of bounds.'); // Remove input. var input = this.inputList[inputIndex]; this.inputList.splice(inputIndex, 1); diff --git a/core/blockly.js b/core/blockly.js index b835cc3bc..bb1fa9759 100644 --- a/core/blockly.js +++ b/core/blockly.js @@ -453,10 +453,9 @@ Blockly.bindEventWithChecks_ = function(node, name, thisObject, func, e.preventDefault(); } }; - for (var i = 0, eventName; - eventName = Blockly.Touch.TOUCH_MAP[name][i]; i++) { - node.addEventListener(eventName, touchWrapFunc, false); - bindData.push([node, eventName, touchWrapFunc]); + for (var i = 0, type; type = Blockly.Touch.TOUCH_MAP[name][i]; i++) { + node.addEventListener(type, touchWrapFunc, false); + bindData.push([node, type, touchWrapFunc]); } } return bindData; @@ -503,10 +502,9 @@ Blockly.bindEvent_ = function(node, name, thisObject, func) { // Stop the browser from scrolling/zooming the page. e.preventDefault(); }; - for (var i = 0, eventName; - eventName = Blockly.Touch.TOUCH_MAP[name][i]; i++) { - node.addEventListener(eventName, touchWrapFunc, false); - bindData.push([node, eventName, touchWrapFunc]); + for (var i = 0, type; type = Blockly.Touch.TOUCH_MAP[name][i]; i++) { + node.addEventListener(type, touchWrapFunc, false); + bindData.push([node, type, touchWrapFunc]); } } return bindData; diff --git a/core/scrollbar.js b/core/scrollbar.js index 3849a6385..ec0458e31 100644 --- a/core/scrollbar.js +++ b/core/scrollbar.js @@ -43,14 +43,18 @@ goog.require('goog.events'); */ Blockly.ScrollbarPair = function(workspace) { this.workspace_ = workspace; - this.hScroll = new Blockly.Scrollbar(workspace, true, true, - 'blocklyMainWorkspaceScrollbar'); - this.vScroll = new Blockly.Scrollbar(workspace, false, true, - 'blocklyMainWorkspaceScrollbar'); - this.corner_ = Blockly.utils.createSvgElement('rect', - {'height': Blockly.Scrollbar.scrollbarThickness, - 'width': Blockly.Scrollbar.scrollbarThickness, - 'class': 'blocklyScrollbarBackground'}, null); + this.hScroll = new Blockly.Scrollbar( + workspace, true, true, 'blocklyMainWorkspaceScrollbar'); + this.vScroll = new Blockly.Scrollbar( + workspace, false, true, 'blocklyMainWorkspaceScrollbar'); + this.corner_ = Blockly.utils.createSvgElement( + 'rect', + { + 'height': Blockly.Scrollbar.scrollbarThickness, + 'width': Blockly.Scrollbar.scrollbarThickness, + 'class': 'blocklyScrollbarBackground' + }, + null); Blockly.utils.insertAfter_(this.corner_, workspace.getBubbleCanvas()); }; @@ -210,24 +214,20 @@ Blockly.Scrollbar = function(workspace, horizontal, opt_pair, opt_class) { */ this.position_ = new goog.math.Coordinate(0, 0); + // Store the thickness in a temp variable for readability. + var scrollbarThickness = Blockly.Scrollbar.scrollbarThickness; if (horizontal) { - this.svgBackground_.setAttribute('height', - Blockly.Scrollbar.scrollbarThickness); - this.outerSvg_.setAttribute('height', - Blockly.Scrollbar.scrollbarThickness); - this.svgHandle_.setAttribute('height', - Blockly.Scrollbar.scrollbarThickness - 5); + this.svgBackground_.setAttribute('height', scrollbarThickness); + this.outerSvg_.setAttribute('height', scrollbarThickness); + this.svgHandle_.setAttribute('height', scrollbarThickness - 5); this.svgHandle_.setAttribute('y', 2.5); this.lengthAttribute_ = 'width'; this.positionAttribute_ = 'x'; } else { - this.svgBackground_.setAttribute('width', - Blockly.Scrollbar.scrollbarThickness); - this.outerSvg_.setAttribute('width', - Blockly.Scrollbar.scrollbarThickness); - this.svgHandle_.setAttribute('width', - Blockly.Scrollbar.scrollbarThickness - 5); + this.svgBackground_.setAttribute('width', scrollbarThickness); + this.outerSvg_.setAttribute('width', scrollbarThickness); + this.svgHandle_.setAttribute('width', scrollbarThickness - 5); this.svgHandle_.setAttribute('x', 2.5); this.lengthAttribute_ = 'height'; @@ -609,17 +609,21 @@ Blockly.Scrollbar.prototype.createDom_ = function(opt_class) { if (opt_class) { className += ' ' + opt_class; } - this.outerSvg_ = Blockly.utils.createSvgElement('svg', {'class': className}, - null); + this.outerSvg_ = Blockly.utils.createSvgElement( + 'svg', {'class': className}, null); this.svgGroup_ = Blockly.utils.createSvgElement('g', {}, this.outerSvg_); - this.svgBackground_ = Blockly.utils.createSvgElement('rect', - {'class': 'blocklyScrollbarBackground'}, this.svgGroup_); + this.svgBackground_ = Blockly.utils.createSvgElement( + 'rect', {'class': 'blocklyScrollbarBackground'}, this.svgGroup_); var radius = Math.floor((Blockly.Scrollbar.scrollbarThickness - 5) / 2); - this.svgHandle_ = Blockly.utils.createSvgElement('rect', - {'class': 'blocklyScrollbarHandle', 'rx': radius, 'ry': radius}, + this.svgHandle_ = Blockly.utils.createSvgElement( + 'rect', + { + 'class': 'blocklyScrollbarHandle', + 'rx': radius, + 'ry': radius + }, this.svgGroup_); - Blockly.utils.insertAfter_(this.outerSvg_, - this.workspace_.getParentSvg()); + Blockly.utils.insertAfter_(this.outerSvg_, this.workspace_.getParentSvg()); }; /** diff --git a/core/touch_gesture.js b/core/touch_gesture.js index 3150835fe..26adc0fcc 100644 --- a/core/touch_gesture.js +++ b/core/touch_gesture.js @@ -47,8 +47,7 @@ goog.require('goog.math.Coordinate'); * @constructor */ Blockly.TouchGesture = function(e, creatorWorkspace) { - Blockly.TouchGesture.superClass_.constructor.call(this, e, - creatorWorkspace); + Blockly.TouchGesture.superClass_.constructor.call(this, e, creatorWorkspace); /** * Boolean for whether or not this gesture is a multi-touch gesture. @@ -126,11 +125,14 @@ Blockly.TouchGesture.prototype.doStart = function(e) { */ Blockly.TouchGesture.prototype.bindMouseEvents = function(e) { this.onStartWrapper_ = Blockly.bindEventWithChecks_( - document, 'mousedown', null, this.handleStart.bind(this), /*opt_noCaptureIdentifier*/ true); + document, 'mousedown', null, this.handleStart.bind(this), + /*opt_noCaptureIdentifier*/ true); this.onMoveWrapper_ = Blockly.bindEventWithChecks_( - document, 'mousemove', null, this.handleMove.bind(this), /*opt_noCaptureIdentifier*/ true); + document, 'mousemove', null, this.handleMove.bind(this), + /*opt_noCaptureIdentifier*/ true); this.onUpWrapper_ = Blockly.bindEventWithChecks_( - document, 'mouseup', null, this.handleUp.bind(this), /*opt_noCaptureIdentifier*/ true); + document, 'mouseup', null, this.handleUp.bind(this), + /*opt_noCaptureIdentifier*/ true); e.preventDefault(); }; @@ -259,7 +261,7 @@ Blockly.TouchGesture.prototype.handleTouchMove = function(e) { var moveDistance = goog.math.Coordinate.distance(point0, point1); var startDistance = this.startDistance_; var scale = this.touchScale_ = moveDistance / startDistance; - + if (this.previousScale_ > 0 && this.previousScale_ < Infinity) { var gestureScale = scale - this.previousScale_; var delta = gestureScale > 0 ? @@ -301,7 +303,7 @@ Blockly.TouchGesture.prototype.getTouchPoint = function(e) { return null; } return new goog.math.Coordinate( - (e.pageX ? e.pageX : e.changedTouches[0].pageX), - (e.pageY ? e.pageY : e.changedTouches[0].pageY) + (e.pageX ? e.pageX : e.changedTouches[0].pageX), + (e.pageY ? e.pageY : e.changedTouches[0].pageY) ); }; diff --git a/core/warning.js b/core/warning.js index d0dffff43..6805d42c2 100644 --- a/core/warning.js +++ b/core/warning.js @@ -87,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', diff --git a/core/workspace_svg.js b/core/workspace_svg.js index 64e22d4ea..2f78a1663 100644 --- a/core/workspace_svg.js +++ b/core/workspace_svg.js @@ -1271,8 +1271,8 @@ Blockly.WorkspaceSvg.prototype.showContextMenu_ = function(e) { if (deleteList.length < 2 ) { deleteNext(); } else { - Blockly.confirm(Blockly.Msg.DELETE_ALL_BLOCKS. - replace('%1', deleteList.length), + Blockly.confirm( + Blockly.Msg.DELETE_ALL_BLOCKS.replace('%1', deleteList.length), function(ok) { if (ok) { deleteNext();