diff --git a/src/brushes/base_brush.class.js b/src/brushes/base_brush.class.js index 461d18ed..ca22f125 100644 --- a/src/brushes/base_brush.class.js +++ b/src/brushes/base_brush.class.js @@ -71,7 +71,9 @@ fabric.BaseBrush = fabric.util.createClass(/** @lends fabric.BaseBrush.prototype * @private */ _setShadow: function() { - if (!this.shadow) return; + if (!this.shadow) { + return; + } var ctx = this.canvas.contextTop; diff --git a/src/canvas.class.js b/src/canvas.class.js index 653ae932..0a4f8a04 100644 --- a/src/canvas.class.js +++ b/src/canvas.class.js @@ -339,7 +339,9 @@ * @param {fabric.Object} target */ _shouldCenterTransform: function (e, target) { - if (!target) return; + if (!target) { + return; + } var t = this._currentTransform, centerTransform; @@ -403,7 +405,9 @@ * @param {fabric.Object} target */ _setupCurrentTransform: function (e, target) { - if (!target) return; + if (!target) { + return; + } var pointer = this.getPointer(e), corner = target._findTargetCorner(this.getPointer(e, true)), @@ -472,7 +476,9 @@ lockScalingX = target.get('lockScalingX'), lockScalingY = target.get('lockScalingY'); - if (lockScalingX && lockScalingY) return; + if (lockScalingX && lockScalingY) { + return; + } // Get the constraint point var constraintPosition = target.translateToOriginPoint(target.getCenterPoint(), t.originX, t.originY), @@ -623,7 +629,9 @@ var t = this._currentTransform; - if (t.target.get('lockRotation')) return; + if (t.target.get('lockRotation')) { + return; + } var lastAngle = atan2(t.ey - t.top, t.ex - t.left), curAngle = atan2(y - t.top, x - t.left), @@ -722,7 +730,9 @@ * @param {Boolean} skipGroup when true, group is skipped and only objects are traversed through */ findTarget: function (e, skipGroup) { - if (this.skipTargetFind) return; + if (this.skipTargetFind) { + return; + } if (this._isLastRenderedObject(e)) { return this.lastRenderedObjectWithControlsAboveOverlay; @@ -1102,7 +1112,9 @@ */ _drawObjectsControls: function(ctx) { for (var i = 0, len = this._objects.length; i < len; ++i) { - if (!this._objects[i] || !this._objects[i].active) continue; + if (!this._objects[i] || !this._objects[i].active) { + continue; + } this._objects[i]._renderControls(ctx); this.lastRenderedObjectWithControlsAboveOverlay = this._objects[i]; } diff --git a/src/color.class.js b/src/color.class.js index 35393c4d..8fc5d6fc 100644 --- a/src/color.class.js +++ b/src/color.class.js @@ -394,7 +394,9 @@ */ fabric.Color.sourceFromHsl = function(color) { var match = color.match(Color.reHSLa); - if (!match) return; + if (!match) { + return; + } var h = (((parseFloat(match[1]) % 360) + 360) % 360) / 360, s = parseFloat(match[2]) / (/%$/.test(match[2]) ? 100 : 1), diff --git a/src/filters/blend_filter.class.js b/src/filters/blend_filter.class.js index 33be971c..7b87def0 100644 --- a/src/filters/blend_filter.class.js +++ b/src/filters/blend_filter.class.js @@ -38,12 +38,12 @@ var context = canvasEl.getContext('2d'), imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height), data = imageData.data, - tr, tg, tb, - r, g, b, - source, + tr, tg, tb, + r, g, b, + source, isImage = false; - if(this.image){ + if (this.image) { // Blend images isImage = true; @@ -51,12 +51,13 @@ _el.width = this.image.width; _el.height = this.image.height; - var _tmp_canvas = new fabric.StaticCanvas(_el); - _tmp_canvas.add(this.image); - var context2 = _tmp_canvas.getContext('2d'); - source = context2.getImageData(0, 0, _tmp_canvas.width, _tmp_canvas.height).data; - } else { - // Blend color + var tmpCanvas = new fabric.StaticCanvas(_el); + tmpCanvas.add(this.image); + var context2 = tmpCanvas.getContext('2d'); + source = context2.getImageData(0, 0, tmpCanvas.width, tmpCanvas.height).data; + } + else { + // Blend color source = new fabric.Color(this.color).getSource(); tr = source[0] * this.alpha; @@ -70,22 +71,22 @@ g = data[i + 1]; b = data[i + 2]; - if(isImage){ + if (isImage) { tr = source[i] * this.alpha; tg = source[i + 1] * this.alpha; tb = source[i + 2] * this.alpha; } - switch(this.mode){ + switch (this.mode) { case 'multiply': data[i] = r * tr / 255; data[i + 1] = g * tg / 255; data[i + 2] = b * tb / 255; break; case 'screen': - data[i] = 1 - (1-r) * (1-tr); - data[i + 1] = 1 - (1-g) * (1-tg); - data[i + 2] = 1 - (1-b) * (1-tb); + data[i] = 1 - (1 - r) * (1 - tr); + data[i + 1] = 1 - (1 - g) * (1 - tg); + data[i + 2] = 1 - (1 - b) * (1 - tb); break; case 'add': data[i] = Math.min(255, r + tr); diff --git a/src/filters/convolute_filter.class.js b/src/filters/convolute_filter.class.js index 3aef4ab3..8a131116 100644 --- a/src/filters/convolute_filter.class.js +++ b/src/filters/convolute_filter.class.js @@ -125,7 +125,9 @@ scx = sx + cx - halfSide; /* jshint maxdepth:5 */ - if (scy < 0 || scy > sh || scx < 0 || scx > sw) continue; + if (scy < 0 || scy > sh || scx < 0 || scx > sw) { + continue; + } var srcOff = (scy * sw + scx) * 4, wt = weights[cy * side + cx]; diff --git a/src/filters/mask_filter.class.js b/src/filters/mask_filter.class.js index 7b7c457c..5133a95a 100644 --- a/src/filters/mask_filter.class.js +++ b/src/filters/mask_filter.class.js @@ -41,7 +41,9 @@ * @param {Object} canvasEl Canvas element to apply filter to */ applyTo: function(canvasEl) { - if (!this.mask) return; + if (!this.mask) { + return; + } var context = canvasEl.getContext('2d'), imageData = context.getImageData(0, 0, canvasEl.width, canvasEl.height), diff --git a/src/gradient.class.js b/src/gradient.class.js index 6e58c16e..5a42c6cb 100644 --- a/src/gradient.class.js +++ b/src/gradient.class.js @@ -165,6 +165,7 @@ if (this.type === 'linear') { markup = [ + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ]; } else if (this.type === 'radial') { markup = [ + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ]; } for (var i = 0; i < this.colorStops.length; i++) { markup.push( + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ); } @@ -213,7 +219,9 @@ toLive: function(ctx) { var gradient; - if (!this.type) return; + if (!this.type) { + return; + } if (this.type === 'linear') { gradient = ctx.createLinearGradient( diff --git a/src/log.js b/src/log.js index 22d23763..7c34d32a 100644 --- a/src/log.js +++ b/src/log.js @@ -1,12 +1,12 @@ /** * Wrapper around `console.log` (when available) - * @param {Any} values Values to log + * @param {Any} [values] Values to log */ fabric.log = function() { }; /** * Wrapper around `console.warn` (when available) - * @param {Any} Values to log as a warning + * @param {Any} [values] Values to log as a warning */ fabric.warn = function() { }; diff --git a/src/mixins/animation.mixin.js b/src/mixins/animation.mixin.js index b937d49e..56db8915 100644 --- a/src/mixins/animation.mixin.js +++ b/src/mixins/animation.mixin.js @@ -119,8 +119,8 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prototype */ { /** * Animates object's properties - * @param {String|Object} property to animate (if string) or properties to animate (if object) - * @param {Number|Object} value to animate property to (if string was given first) or options object + * @param {String|Object} property Property to animate (if string) or properties to animate (if object) + * @param {Number|Object} value Value to animate property to (if string was given first) or options object * @return {fabric.Object} thisArg * @tutorial {@link http://fabricjs.com/fabric-intro-part-2/#animation} * @chainable @@ -208,11 +208,15 @@ fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prot else { _this.set(property, value); } - if (skipCallbacks) return; + if (skipCallbacks) { + return; + } options.onChange && options.onChange(); }, onComplete: function() { - if (skipCallbacks) return; + if (skipCallbacks) { + return; + } _this.setCoords(); options.onComplete && options.onComplete(); diff --git a/src/mixins/canvas_events.mixin.js b/src/mixins/canvas_events.mixin.js index 09f26a24..fb093bd1 100644 --- a/src/mixins/canvas_events.mixin.js +++ b/src/mixins/canvas_events.mixin.js @@ -379,7 +379,9 @@ // accept only left clicks var isLeftClick = 'which' in e ? e.which === 1 : e.button === 1; - if (!isLeftClick && !fabric.isTouchSupported) return; + if (!isLeftClick && !fabric.isTouchSupported) { + return; + } if (this.isDrawingMode) { this._onMouseDownInDrawingMode(e); @@ -387,7 +389,9 @@ } // ignore if some object is being transformed at this moment - if (this._currentTransform) return; + if (this._currentTransform) { + return; + } var target = this.findTarget(e), pointer = this.getPointer(e, true); diff --git a/src/mixins/canvas_gestures.mixin.js b/src/mixins/canvas_gestures.mixin.js index b8dcfcf3..ea56e733 100644 --- a/src/mixins/canvas_gestures.mixin.js +++ b/src/mixins/canvas_gestures.mixin.js @@ -70,7 +70,9 @@ lockScalingX = target.get('lockScalingX'), lockScalingY = target.get('lockScalingY'); - if (lockScalingX && lockScalingY) return; + if (lockScalingX && lockScalingY) { + return; + } target._scaling = true; @@ -97,7 +99,9 @@ _rotateObjectByAngle: function(curAngle) { var t = this._currentTransform; - if (t.target.get('lockRotation')) return; + if (t.target.get('lockRotation')) { + return; + } t.target.angle = radiansToDegrees(degreesToRadians(curAngle) + t.theta); } }); diff --git a/src/mixins/canvas_grouping.mixin.js b/src/mixins/canvas_grouping.mixin.js index bee95e87..e0821a43 100644 --- a/src/mixins/canvas_grouping.mixin.js +++ b/src/mixins/canvas_grouping.mixin.js @@ -156,7 +156,9 @@ for (var i = this._objects.length; i--; ) { currentObject = this._objects[i]; - if (!currentObject || !currentObject.selectable || !currentObject.visible) continue; + if (!currentObject || !currentObject.selectable || !currentObject.visible) { + continue; + } if (currentObject.intersectsWithRect(selectionX1Y1, selectionX2Y2) || currentObject.isContainedWithinRect(selectionX1Y1, selectionX2Y2) || @@ -167,7 +169,9 @@ group.push(currentObject); // only add one object if it's a click - if (isClick) break; + if (isClick) { + break; + } } } diff --git a/src/mixins/canvas_serialization.mixin.js b/src/mixins/canvas_serialization.mixin.js index 907c87a5..31c8803f 100644 --- a/src/mixins/canvas_serialization.mixin.js +++ b/src/mixins/canvas_serialization.mixin.js @@ -39,7 +39,9 @@ fabric.util.object.extend(fabric.StaticCanvas.prototype, /** @lends fabric.Stati * }); */ loadFromJSON: function (json, callback, reviver) { - if (!json) return; + if (!json) { + return; + } // serialize if it wasn't already var serialized = (typeof json === 'string') diff --git a/src/mixins/itext.svg_export.js b/src/mixins/itext.svg_export.js index bf75214f..bfb1758f 100644 --- a/src/mixins/itext.svg_export.js +++ b/src/mixins/itext.svg_export.js @@ -71,6 +71,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot */ _createTextCharBg: function(styleDecl, lineLeftOffset, lineTopOffset, heightOfLine, charWidth, charOffset) { return [ + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ].join(''); }, @@ -96,6 +98,7 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot }, styleDecl)); return [ + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ].join(''); } }); diff --git a/src/mixins/itext_behavior.mixin.js b/src/mixins/itext_behavior.mixin.js index 044473db..e91a48f0 100644 --- a/src/mixins/itext_behavior.mixin.js +++ b/src/mixins/itext_behavior.mixin.js @@ -61,11 +61,12 @@ * @private */ _tick: function() { + if (this._abortCursorAnimation) { + return; + } var _this = this; - if (this._abortCursorAnimation) return; - this.animate('_currentCursorOpacity', 1, { duration: this.cursorDuration, @@ -88,7 +89,9 @@ * @private */ _onTickComplete: function() { - if (this._abortCursorAnimation) return; + if (this._abortCursorAnimation) { + return; + } var _this = this; if (this._cursorTimeout1) { @@ -315,7 +318,9 @@ * @chainable */ enterEditing: function() { - if (this.isEditing || !this.editable) return; + if (this.isEditing || !this.editable) { + return; + } this.exitEditingOnOthers(); @@ -364,7 +369,9 @@ * @private */ _updateTextarea: function() { - if (!this.hiddenTextarea) return; + if (!this.hiddenTextarea) { + return; + } this.hiddenTextarea.value = this.text; this.hiddenTextarea.selectionStart = this.selectionStart; @@ -389,7 +396,9 @@ * @private */ _restoreEditingProps: function() { - if (!this._savedProps) return; + if (!this._savedProps) { + return; + } this.hoverCursor = this._savedProps.overCursor; this.hasControls = this._savedProps.hasControls; @@ -575,7 +584,9 @@ insertStyleObjects: function(_chars, isEndOfLine, styles) { // short-circuit - if (this.isEmptyStyles()) return; + if (this.isEmptyStyles()) { + return; + } var cursorLocation = this.get2DCursorLocation(), lineIndex = cursorLocation.lineIndex, diff --git a/src/mixins/itext_click_behavior.mixin.js b/src/mixins/itext_click_behavior.mixin.js index b55fd814..6a1e4a96 100644 --- a/src/mixins/itext_click_behavior.mixin.js +++ b/src/mixins/itext_click_behavior.mixin.js @@ -112,7 +112,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot */ initMousemoveHandler: function() { this.on('mousemove', function(options) { - if (!this.__isMousedown || !this.isEditing) return; + if (!this.__isMousedown || !this.isEditing) { + return; + } var newSelectionStart = this.getSelectionStartFromPointer(options.e); @@ -143,7 +145,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot initMouseupHandler: function() { this.on('mouseup', function(options) { this.__isMousedown = false; - if (this._isObjectMoved(options.e)) return; + if (this._isObjectMoved(options.e)) { + return; + } if (this.__lastSelected) { this.enterEditing(); diff --git a/src/mixins/itext_key_behavior.mixin.js b/src/mixins/itext_key_behavior.mixin.js index 1d39159e..c83aad64 100644 --- a/src/mixins/itext_key_behavior.mixin.js +++ b/src/mixins/itext_key_behavior.mixin.js @@ -53,7 +53,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot * @param {Event} e Event object */ onKeyDown: function(e) { - if (!this.isEditing) return; + if (!this.isEditing) { + return; + } if (e.keyCode in this._keysMap) { this[this._keysMap[e.keyCode]](e); @@ -442,7 +444,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot * @param {Event} e Event object */ moveCursorLeft: function(e) { - if (this.selectionStart === 0 && this.selectionEnd === 0) return; + if (this.selectionStart === 0 && this.selectionEnd === 0) { + return; + } this.abortCursorAnimation(); this._currentCursorOpacity = 1; @@ -528,7 +532,9 @@ fabric.util.object.extend(fabric.IText.prototype, /** @lends fabric.IText.protot * @param {Event} e Event object */ moveCursorRight: function(e) { - if (this.selectionStart >= this.text.length && this.selectionEnd >= this.text.length) return; + if (this.selectionStart >= this.text.length && this.selectionEnd >= this.text.length) { + return; + } this.abortCursorAnimation(); this._currentCursorOpacity = 1; diff --git a/src/mixins/object_interactivity.mixin.js b/src/mixins/object_interactivity.mixin.js index 3d7f87b5..59ec95b7 100644 --- a/src/mixins/object_interactivity.mixin.js +++ b/src/mixins/object_interactivity.mixin.js @@ -1,7 +1,9 @@ (function(){ var degreesToRadians = fabric.util.degreesToRadians, + //jscs:disable requireCamelCaseOrUpperCaseIdentifiers isVML = function() { return typeof G_vmlCanvasManager !== 'undefined'; }; + //jscs:enable requireCamelCaseOrUpperCaseIdentifiers fabric.util.object.extend(fabric.Object.prototype, /** @lends fabric.Object.prototype */ { @@ -262,7 +264,9 @@ * @chainable */ drawBorders: function(ctx) { - if (!this.hasBorders) return this; + if (!this.hasBorders) { + return this; + } var padding = this.padding, padding2 = padding * 2, @@ -337,7 +341,9 @@ * @chainable */ drawControls: function(ctx) { - if (!this.hasControls) return this; + if (!this.hasControls) { + return this; + } var size = this.cornerSize, size2 = size / 2, diff --git a/src/mixins/observable.mixin.js b/src/mixins/observable.mixin.js index 9c7774e0..e467da02 100644 --- a/src/mixins/observable.mixin.js +++ b/src/mixins/observable.mixin.js @@ -6,7 +6,9 @@ * @param {Function} handler */ function _removeEventListener(eventName, handler) { - if (!this.__eventListeners[eventName]) return; + if (!this.__eventListeners[eventName]) { + return; + } if (handler) { fabric.util.removeFromArray(this.__eventListeners[eventName], handler); @@ -57,7 +59,9 @@ * @chainable */ function stopObserving(eventName, handler) { - if (!this.__eventListeners) return; + if (!this.__eventListeners) { + return; + } // remove all key/value pairs (event name -> event handler) if (arguments.length === 0) { @@ -86,10 +90,15 @@ * @chainable */ function fire(eventName, options) { - if (!this.__eventListeners) return; + if (!this.__eventListeners) { + return; + } var listenersForEvent = this.__eventListeners[eventName]; - if (!listenersForEvent) return; + if (!listenersForEvent) { + return; + } + for (var i = 0, len = listenersForEvent.length; i < len; i++) { // avoiding try/catch for perf. reasons listenersForEvent[i].call(this, options || { }); diff --git a/src/parser.js b/src/parser.js index 2a6ca24c..9b1ce184 100644 --- a/src/parser.js +++ b/src/parser.js @@ -101,9 +101,13 @@ function _setStrokeFillOpacity(attributes) { for (var attr in colorAttributes) { - if (!attributes[attr] || typeof attributes[colorAttributes[attr]] === 'undefined') continue; + if (!attributes[attr] || typeof attributes[colorAttributes[attr]] === 'undefined') { + continue; + } - if (attributes[attr].indexOf('url(') === 0) continue; + if (attributes[attr].indexOf('url(') === 0) { + continue; + } var color = new fabric.Color(attributes[attr]); attributes[attr] = color.setAlpha(toFixed(color.getAlpha() * attributes[colorAttributes[attr]], 2)).toRgba(); @@ -271,7 +275,9 @@ // TODO: support non-px font size var match = value.match(/(normal|italic)?\s*(normal|small-caps)?\s*(normal|bold|bolder|lighter|100|200|300|400|500|600|700|800|900)?\s*(\d+)px(?:\/(normal|[\d\.]+))?\s+(.*)/); - if (!match) return; + if (!match) { + return; + } var fontStyle = match[1], // font variant is not used @@ -324,7 +330,9 @@ function parseStyleObject(style, oStyle) { var attr, value; for (var prop in style) { - if (typeof style[prop] === 'undefined') continue; + if (typeof style[prop] === 'undefined') { + continue; + } attr = normalizeAttr(prop.toLowerCase()); value = normalizeValue(attr, style[prop]); @@ -343,7 +351,7 @@ */ function getGlobalStylesForElement(element) { var styles = { }; - + for (var rule in fabric.cssRules) { if (elementMatchesRule(element, rule.split(' '))) { for (var property in fabric.cssRules[rule]) { @@ -419,7 +427,9 @@ for (var j = 0, attrs = el.attributes, l = attrs.length; j < l; j++) { var attr = attrs.item(j); - if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') continue; + if (attr.nodeName === 'x' || attr.nodeName === 'y' || attr.nodeName === 'xlink:href') { + continue; + } if (attr.nodeName === 'transform') { currentTrans = currentTrans + ' ' + attr.nodeValue; @@ -441,7 +451,9 @@ */ function addSvgTransform(doc, matrix) { matrix[3] = matrix[0] = (matrix[0] > matrix[3] ? matrix[3] : matrix[0]); - if (!(matrix[0] !== 1 || matrix[3] !== 1 || matrix[4] !== 0 || matrix[5] !== 0)) return; + if (!(matrix[0] !== 1 || matrix[3] !== 1 || matrix[4] !== 0 || matrix[5] !== 0)) { + return; + } // default is to preserve aspect ratio // preserveAspectRatio attribute to be implemented var el = doc.ownerDocument.createElement('g'); @@ -490,7 +502,9 @@ } return function(doc, callback, reviver) { - if (!doc) return; + if (!doc) { + return; + } var startTime = new Date(); parseUseDirectives(doc); @@ -626,7 +640,9 @@ for (var i = instances.length; i--; ) { var instanceFillValue = instances[i].get('fill'); - if (!(/^url\(/).test(instanceFillValue)) continue; + if (!(/^url\(/).test(instanceFillValue)) { + continue; + } var gradientId = instanceFillValue.slice(5, instanceFillValue.length - 1); @@ -756,7 +772,9 @@ parsePointsAttribute: function(points) { // points attribute is required and must not be empty - if (!points) return null; + if (!points) { + return null; + } // replace commas with whitespace and remove bookending whitespace points = points.replace(/,/g, ' ').trim(); @@ -858,7 +876,9 @@ //IE chokes on DOCTYPE xml.loadXML(r.responseText.replace(//i,'')); } - if (!xml || !xml.documentElement) return; + if (!xml || !xml.documentElement) { + return; + } fabric.parseSVGDocument(xml.documentElement, function (results, options) { svgCache.set(url, { @@ -907,23 +927,29 @@ var markup = ''; for (var i = 0, len = objects.length; i < len; i++) { - if (objects[i].type !== 'text' || !objects[i].path) continue; + if (objects[i].type !== 'text' || !objects[i].path) { + continue; + } markup += [ + //jscs:disable validateIndentation '@font-face {', 'font-family: ', objects[i].fontFamily, '; ', 'src: url(\'', objects[i].path, '\')', '}' + //jscs:enable validateIndentation ].join(''); } if (markup) { markup = [ + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ].join(''); } diff --git a/src/shapes/ellipse.class.js b/src/shapes/ellipse.class.js index 93116815..678ae63f 100644 --- a/src/shapes/ellipse.class.js +++ b/src/shapes/ellipse.class.js @@ -99,7 +99,9 @@ */ render: function(ctx, noTransform) { // do not use `get` for perf. reasons - if (this.rx === 0 || this.ry === 0) return; + if (this.rx === 0 || this.ry === 0) { + return; + } return this.callSuper('render', ctx, noTransform); }, diff --git a/src/shapes/group.class.js b/src/shapes/group.class.js index 756af1d8..5dace2a8 100644 --- a/src/shapes/group.class.js +++ b/src/shapes/group.class.js @@ -115,8 +115,8 @@ addWithUpdate: function(object) { this._restoreObjectsState(); if (object) { - this._objects.push(object); - object.group = this; + this._objects.push(object); + object.group = this; } // since _restoreObjectsState set objects inactive this.forEachObject(this._setObjectActive, this); @@ -218,7 +218,9 @@ */ render: function(ctx) { // do not render if object is not visible - if (!this.visible) return; + if (!this.visible) { + return; + } ctx.save(); this.clipTo && fabric.util.clipContext(this, ctx); @@ -252,7 +254,9 @@ var originalHasRotatingPoint = object.hasRotatingPoint; // do not render if object is not visible - if (!object.visible) return; + if (!object.visible) { + return; + } object.hasRotatingPoint = false; @@ -475,9 +479,11 @@ */ toSVG: function(reviver) { var markup = [ + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ]; for (var i = 0, len = this._objects.length; i < len; i++) { diff --git a/src/shapes/image.class.js b/src/shapes/image.class.js index 7a9b84db..849dc2a8 100644 --- a/src/shapes/image.class.js +++ b/src/shapes/image.class.js @@ -119,7 +119,9 @@ */ render: function(ctx, noTransform) { // do not render if object is not visible - if (!this.visible) return; + if (!this.visible) { + return; + } ctx.save(); var m = this.transformMatrix, diff --git a/src/shapes/itext.class.js b/src/shapes/itext.class.js index 87af2adc..d1c3c52c 100644 --- a/src/shapes/itext.class.js +++ b/src/shapes/itext.class.js @@ -201,7 +201,9 @@ * Returns true if object has no styling */ isEmptyStyles: function() { - if (!this.styles) return true; + if (!this.styles) { + return true; + } var obj = this.styles; for (var p1 in obj) { @@ -313,7 +315,9 @@ * Renders cursor or selection (depending on what exists) */ renderCursorOrSelection: function() { - if (!this.active) return; + if (!this.active) { + return; + } var chars = this.text.split(''), boundaries; @@ -729,7 +733,9 @@ fontSize = (styleDeclaration ? styleDeclaration.fontSize : null) || this.fontSize; - if (!textDecoration) return; + if (!textDecoration) { + return; + } if (textDecoration.indexOf('underline') > -1) { this._renderCharDecorationAtOffset( @@ -800,7 +806,9 @@ * @param {Array} textLines Array of all text lines */ _renderTextLinesBackground: function(ctx, textLines) { - if (!this.textBackgroundColor && !this.styles) return; + if (!this.textBackgroundColor && !this.styles) { + return; + } ctx.save(); @@ -1101,7 +1109,9 @@ * @private */ _renderTextBoxBackground: function(ctx) { - if (!this.backgroundColor) return; + if (!this.backgroundColor) { + return; + } ctx.save(); ctx.fillStyle = this.backgroundColor; diff --git a/src/shapes/line.class.js b/src/shapes/line.class.js index d00a5311..204dcd5f 100644 --- a/src/shapes/line.class.js +++ b/src/shapes/line.class.js @@ -164,7 +164,9 @@ cp.x, cp.y ); - if (!this.transformMatrix) ctx.translate(-this.group.width / 2, -this.group.height / 2); + if (!this.transformMatrix) { + ctx.translate(-this.group.width / 2, -this.group.height / 2); + } } if (!this.strokeDashArray || this.strokeDashArray && supportsLineDash) { diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 7406e8f2..96cef203 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -708,7 +708,9 @@ * @param {Object} [options] Options object */ _initClipping: function(options) { - if (!options.clipTo || typeof options.clipTo !== 'string') return; + if (!options.clipTo || typeof options.clipTo !== 'string') { + return; + } var functionBody = fabric.util.getFunctionBody(options.clipTo); if (typeof functionBody !== 'undefined') { @@ -932,8 +934,9 @@ * @return {Boolean} flipY value // TODO */ getViewportTransform: function() { - if (this.canvas && this.canvas.viewportTransform) + if (this.canvas && this.canvas.viewportTransform) { return this.canvas.viewportTransform; + } return [1, 0, 0, 1, 0, 0]; }, @@ -944,7 +947,9 @@ */ render: function(ctx, noTransform) { // do not render if width/height are zeros or object is not visible - if (this.width === 0 || this.height === 0 || !this.visible) return; + if (this.width === 0 || this.height === 0 || !this.visible) { + return; + } ctx.save(); @@ -1036,7 +1041,9 @@ * @param {CanvasRenderingContext2D} ctx Context to render on */ _setShadow: function(ctx) { - if (!this.shadow) return; + if (!this.shadow) { + return; + } ctx.shadowColor = this.shadow.color; ctx.shadowBlur = this.shadow.blur; @@ -1049,7 +1056,9 @@ * @param {CanvasRenderingContext2D} ctx Context to render on */ _removeShadow: function(ctx) { - if (!this.shadow) return; + if (!this.shadow) { + return; + } ctx.shadowColor = ''; ctx.shadowBlur = ctx.shadowOffsetX = ctx.shadowOffsetY = 0; @@ -1060,7 +1069,9 @@ * @param {CanvasRenderingContext2D} ctx Context to render on */ _renderFill: function(ctx) { - if (!this.fill) return; + if (!this.fill) { + return; + } if (this.fill.toLive) { ctx.save(); @@ -1087,7 +1098,9 @@ * @param {CanvasRenderingContext2D} ctx Context to render on */ _renderStroke: function(ctx) { - if (!this.stroke || this.strokeWidth === 0) return; + if (!this.stroke || this.strokeWidth === 0) { + return; + } ctx.save(); if (this.strokeDashArray) { diff --git a/src/shapes/path.class.js b/src/shapes/path.class.js index d04e7147..9d70b524 100644 --- a/src/shapes/path.class.js +++ b/src/shapes/path.class.js @@ -94,7 +94,9 @@ // one of commands (m,M,l,L,q,Q,c,C,etc.) followed by non-command characters (i.e. command values) : path.match && path.match(/[mzlhvcsqta][^mzlhvcsqta]*/gi); - if (!this.path) return; + if (!this.path) { + return; + } if (!fromArray) { this.path = this._parsePath(); @@ -455,12 +457,14 @@ */ render: function(ctx, noTransform) { // do not render if object is not visible - if (!this.visible) return; + if (!this.visible) { + return; + } ctx.save(); if (noTransform) { - ctx.translate(-this.width/2, -this.height/2); - } + ctx.translate(-this.width/2, -this.height/2); + } var m = this.transformMatrix; if (m) { @@ -541,6 +545,7 @@ var path = chunks.join(' '); markup.push( + //jscs:disable validateIndentation '', '', '' + //jscs:enable validateIndentation ); return reviver ? reviver(markup.join('')) : markup.join(''); diff --git a/src/shapes/path_group.class.js b/src/shapes/path_group.class.js index e81c51a7..9575dfe3 100644 --- a/src/shapes/path_group.class.js +++ b/src/shapes/path_group.class.js @@ -72,7 +72,9 @@ */ render: function(ctx) { // do not render if object is not visible - if (!this.visible) return; + if (!this.visible) { + return; + } ctx.save(); @@ -148,10 +150,12 @@ toSVG: function(reviver) { var objects = this.getObjects(), markup = [ + //jscs:disable validateIndentation '' + //jscs:enable validateIndentation ]; for (var i = 0, len = objects.length; i < len; i++) { diff --git a/src/shapes/polygon.class.js b/src/shapes/polygon.class.js index 4ece0d16..9039ac6e 100644 --- a/src/shapes/polygon.class.js +++ b/src/shapes/polygon.class.js @@ -67,7 +67,9 @@ this.minX = minX; this.minY = minY; - if (skipOffset) return; + if (skipOffset) { + return; + } var halfWidth = this.width / 2 + this.minX, halfHeight = this.height / 2 + this.minY; diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index f092df60..1f18eed8 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -326,7 +326,9 @@ * @private */ _initDimensions: function() { - if (this.__skipDimension) return; + if (this.__skipDimension) { + return; + } var canvasEl = fabric.util.createCanvasElement(); this._render(canvasEl.getContext('2d')); }, @@ -550,7 +552,9 @@ * @param {Array} textLines Array of all text lines */ _renderTextFill: function(ctx, textLines) { - if (!this.fill && !this._skipFillStrokeCheck) return; + if (!this.fill && !this._skipFillStrokeCheck) { + return; + } this._boundaries = [ ]; var lineHeights = 0; @@ -576,7 +580,9 @@ * @param {Array} textLines Array of all text lines */ _renderTextStroke: function(ctx, textLines) { - if ((!this.stroke || this.strokeWidth === 0) && !this._skipFillStrokeCheck) return; + if ((!this.stroke || this.strokeWidth === 0) && !this._skipFillStrokeCheck) { + return; + } var lineHeights = 0; @@ -626,7 +632,9 @@ * @param {CanvasRenderingContext2D} ctx Context to render on */ _renderTextBoxBackground: function(ctx) { - if (!this.backgroundColor) return; + if (!this.backgroundColor) { + return; + } ctx.save(); ctx.fillStyle = this.backgroundColor; @@ -647,7 +655,9 @@ * @param {Array} textLines Array of all text lines */ _renderTextLinesBackground: function(ctx, textLines) { - if (!this.textBackgroundColor) return; + if (!this.textBackgroundColor) { + return; + } ctx.save(); ctx.fillStyle = this.textBackgroundColor; @@ -703,7 +713,9 @@ * @param {Array} textLines Array of all text lines */ _renderTextDecoration: function(ctx, textLines) { - if (!this.textDecoration) return; + if (!this.textDecoration) { + return; + } // var halfOfVerticalBox = this.originY === 'top' ? 0 : this._getTextHeight(ctx, textLines) / 2; var halfOfVerticalBox = this._getTextHeight(ctx, textLines) / 2, @@ -754,13 +766,16 @@ */ render: function(ctx, noTransform) { // do not render if object is not visible - if (!this.visible) return; + if (!this.visible) { + return; + } ctx.save(); this._transform(ctx, noTransform); - var m = this.transformMatrix; - var isInPathGroup = this.group && this.group.type === 'path-group'; + var m = this.transformMatrix, + isInPathGroup = this.group && this.group.type === 'path-group'; + if (isInPathGroup) { ctx.translate(-this.group.width/2, -this.group.height/2); } @@ -931,7 +946,9 @@ lineTopOffsetMultiplier++; } - if (!this.textBackgroundColor || !this._boundaries) continue; + if (!this.textBackgroundColor || !this._boundaries) { + continue; + } this._setSVGTextLineBg(textBgRects, i, textLeftOffset, lineHeight); } @@ -1087,14 +1104,14 @@ options.originX = 'left'; } - var text = new fabric.Text(element.textContent, options); + var text = new fabric.Text(element.textContent, options), + /* + Adjust positioning: + x/y attributes in SVG correspond to the bottom-left corner of text bounding box + top/left properties in Fabric correspond to center point of text bounding box + */ + offX = 0; - /* - Adjust positioning: - x/y attributes in SVG correspond to the bottom-left corner of text bounding box - top/left properties in Fabric correspond to center point of text bounding box - */ - var offX = 0; if (text.originX === 'left') { offX = text.getWidth() / 2; } diff --git a/src/shapes/text.cufon.js b/src/shapes/text.cufon.js index d86b1e32..63aa47bd 100644 --- a/src/shapes/text.cufon.js +++ b/src/shapes/text.cufon.js @@ -59,9 +59,11 @@ fabric.util.object.extend(fabric.Text.prototype, { // Cufon doesn't play nice with textDecoration=underline if element doesn't have a parent container.appendChild(el); + //jscs:disable requireCamelCaseOrUpperCaseIdentifiers if (typeof G_vmlCanvasManager === 'undefined') { el.innerHTML = this.text; } + //jscs:enable requireCamelCaseOrUpperCaseIdentifiers else { // IE 7 & 8 drop newlines and white space on text nodes // see: http://web.student.tuwien.ac.at/~e0226430/innerHtmlQuirk.html diff --git a/src/static_canvas.class.js b/src/static_canvas.class.js index 2a18ae82..1c04577d 100644 --- a/src/static_canvas.class.js +++ b/src/static_canvas.class.js @@ -421,7 +421,9 @@ this.width = this.width || parseInt(this.lowerCanvasEl.width, 10) || 0; this.height = this.height || parseInt(this.lowerCanvasEl.height, 10) || 0; - if (!this.lowerCanvasEl.style) return; + if (!this.lowerCanvasEl.style) { + return; + } this.lowerCanvasEl.width = this.width; this.lowerCanvasEl.height = this.height; @@ -468,7 +470,7 @@ /** * Sets width of this canvas instance - * @param {Number|String} width value to set width to + * @param {Number|String} value Value to set width to * @param {Object} [options] Options object * @param {Boolean} [options.backstoreOnly=false] Set the given dimensions only as canvas backstore dimensions * @param {Boolean} [options.cssOnly=false] Set the given dimensions only as css dimensions @@ -481,7 +483,7 @@ /** * Sets height of this canvas instance - * @param {Number|String} height value to set height to + * @param {Number|String} value Value to set height to * @param {Object} [options] Options object * @param {Boolean} [options.backstoreOnly=false] Set the given dimensions only as canvas backstore dimensions * @param {Boolean} [options.cssOnly=false] Set the given dimensions only as css dimensions @@ -693,14 +695,18 @@ * @private */ _draw: function (ctx, object) { - if (!object) return; + if (!object) { + return; + } ctx.save(); var v = this.viewportTransform; ctx.transform(v[0], v[1], v[2], v[3], v[4], v[5]); object.render(ctx); ctx.restore(); - if (!this.controlsAboveOverlay) object._renderControls(ctx); + if (!this.controlsAboveOverlay) { + object._renderControls(ctx); + } }, /** diff --git a/src/util/dom_misc.js b/src/util/dom_misc.js index 541cf201..3baebcdd 100644 --- a/src/util/dom_misc.js +++ b/src/util/dom_misc.js @@ -276,7 +276,9 @@ if (loading) { if (typeof this.readyState === 'string' && this.readyState !== 'loaded' && - this.readyState !== 'complete') return; + this.readyState !== 'complete') { + return; + } loading = false; callback(e || fabric.window.event); scriptEl = scriptEl.onload = scriptEl.onreadystatechange = null; diff --git a/src/util/lang_array.js b/src/util/lang_array.js index 2135acc5..96603a64 100644 --- a/src/util/lang_array.js +++ b/src/util/lang_array.js @@ -215,7 +215,9 @@ * @private */ function find(array, byProperty, condition) { - if (!array || array.length === 0) return; + if (!array || array.length === 0) { + return; + } var i = array.length - 1, result = byProperty ? array[i][byProperty] : array[i]; diff --git a/src/util/misc.js b/src/util/misc.js index 823d396e..5bf9de7c 100644 --- a/src/util/misc.js +++ b/src/util/misc.js @@ -387,9 +387,11 @@ */ createCanvasElement: function(canvasEl) { canvasEl || (canvasEl = fabric.document.createElement('canvas')); + //jscs:disable requireCamelCaseOrUpperCaseIdentifiers if (!canvasEl.getContext && typeof G_vmlCanvasManager !== 'undefined') { G_vmlCanvasManager.initElement(canvasEl); } + //jscs:enable requireCamelCaseOrUpperCaseIdentifiers return canvasEl; }, @@ -557,7 +559,9 @@ for (var i = 3, l = imageData.data.length; i < l; i += 4) { var temp = imageData.data[i]; _isTransparent = temp <= 0; - if (_isTransparent === false) break; // Stop if colour found + if (_isTransparent === false) { + break; // Stop if colour found + } } imageData = null;