diff --git a/src/mixins/itext_behavior.mixin.js b/src/mixins/itext_behavior.mixin.js index 897e532b..fad2bfa7 100644 --- a/src/mixins/itext_behavior.mixin.js +++ b/src/mixins/itext_behavior.mixin.js @@ -762,7 +762,9 @@ * @param {Array} copiedStyle array of style objecs */ insertCharStyleObject: function(lineIndex, charIndex, quantity, copiedStyle) { - + if (!this.styles) { + this.styles = {}; + } var currentLineStyles = this.styles[lineIndex], currentLineStylesCloned = clone(currentLineStyles); @@ -780,15 +782,15 @@ } } this._forceClearCache = true; - if (!currentLineStyles) { - return; - } if (copiedStyle) { while (quantity--) { this.styles[lineIndex][charIndex + quantity] = clone(copiedStyle[quantity]); } return; } + if (!currentLineStyles) { + return; + } var newStyle = currentLineStyles[charIndex ? charIndex - 1 : 1]; while (newStyle && quantity--) { this.styles[lineIndex][charIndex + quantity] = clone(newStyle); diff --git a/src/shapes/active_selection.class.js b/src/shapes/active_selection.class.js index f17497c0..c3666c25 100644 --- a/src/shapes/active_selection.class.js +++ b/src/shapes/active_selection.class.js @@ -31,8 +31,7 @@ * @return {Object} thisArg */ initialize: function(objects, options) { - options = options || { }; - + options = options || {}; this._objects = objects || []; for (var i = this._objects.length; i--; ) { this._objects[i].group = this; diff --git a/src/shapes/group.class.js b/src/shapes/group.class.js index 86924574..46a2b9ae 100644 --- a/src/shapes/group.class.js +++ b/src/shapes/group.class.js @@ -66,8 +66,7 @@ * @return {Object} thisArg */ initialize: function(objects, options, isAlreadyGrouped) { - options = options || { }; - + options = options || {}; this._objects = []; // if objects enclosed in a group have been grouped already, // we cannot change properties of objects. diff --git a/src/shapes/itext.class.js b/src/shapes/itext.class.js index dc2808db..c2001052 100644 --- a/src/shapes/itext.class.js +++ b/src/shapes/itext.class.js @@ -179,7 +179,6 @@ * @return {fabric.IText} thisArg */ initialize: function(text, options) { - this.styles = options ? (options.styles || { }) : { }; this.callSuper('initialize', text, options); this.initBehavior(); }, diff --git a/src/shapes/object.class.js b/src/shapes/object.class.js index 86efe8b5..88bd0a4f 100644 --- a/src/shapes/object.class.js +++ b/src/shapes/object.class.js @@ -572,7 +572,6 @@ * @param {Object} [options] Options object */ initialize: function(options) { - options = options || { }; if (options) { this.setOptions(options); } diff --git a/src/shapes/text.class.js b/src/shapes/text.class.js index 431607a5..4a216f65 100644 --- a/src/shapes/text.class.js +++ b/src/shapes/text.class.js @@ -282,7 +282,7 @@ * @return {fabric.Text} thisArg */ initialize: function(text, options) { - options = options || { }; + this.styles = options ? (options.styles || { }) : { }; this.text = text; this.__skipDimension = true; this.callSuper('initialize', options); diff --git a/test/unit/text.js b/test/unit/text.js index d4d7b8d0..91ab7dda 100644 --- a/test/unit/text.js +++ b/test/unit/text.js @@ -54,7 +54,7 @@ 'skewY': 0, 'transformMatrix': null, 'charSpacing': 0, - 'styles': null + 'styles': {} }; var TEXT_SVG = '\t\n\t\t\n\t\t\tx\n\t\t\n\t\n';