diff --git a/src/item/Item.js b/src/item/Item.js index 1f5b7dd4..e861f951 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -72,8 +72,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ else this._setProject(project); } - this._style = new Style(this._project._currentStyle); - this._style._item = this; + this._style = new Style(this._project._currentStyle, this); this._matrix = new Matrix(); if (point) this._matrix.translate(point); @@ -382,7 +381,7 @@ var Item = Base.extend(Callback, /** @lends Item# */{ }, setStyle: function(style) { - this._style.initialize(style); + this._style.set(style); }, hasFill: function() { diff --git a/src/style/Style.js b/src/style/Style.js index b50c250d..fe0df03e 100644 --- a/src/style/Style.js +++ b/src/style/Style.js @@ -202,17 +202,23 @@ var Style = Base.extend(new function() { Item.inject(item); return fields; }, /** @lends Style# */{ - initialize: function Style(style) { + initialize: function Style(style, _item) { // We keep values in a separate object that we can iterate over. this._values = {}; - if (this._item instanceof TextItem) + this._item = _item; + if (_item instanceof TextItem) this._defaults = this._textDefaults; - if (style) { - // If the passed style object is also a Style, clone its clonable - // fields rather than simply copying them. - var isStyle = style instanceof Style, - // Use the other stlyle's _values object for iteration - values = isStyle ? style._values : style; + if (style) + this.set(style); + }, + + set: function(style) { + // If the passed style object is also a Style, clone its clonable + // fields rather than simply copying them. + var isStyle = style instanceof Style, + // Use the other stlyle's _values object for iteration + values = isStyle ? style._values : style; + if (values) { for (var key in values) { if (key in this._defaults) { var value = values[key];