diff --git a/src/item/Item.js b/src/item/Item.js index b50c91e6..02c086d3 100644 --- a/src/item/Item.js +++ b/src/item/Item.js @@ -215,6 +215,7 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ /** * The path style of the item. * + * @name Item#getStyle * @type PathStyle * @bean * @@ -251,13 +252,6 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{ * var path2 = new Path.Circle(new Point(150, 50), 20); * path2.style = myStyle; */ - getStyle: function() { - return this._style; - }, - - setStyle: function(style) { - this._style.initialize(style); - }, statics: { _id: 0 diff --git a/src/style/CharacterStyle.js b/src/style/CharacterStyle.js index 8caeb321..406d42c8 100644 --- a/src/style/CharacterStyle.js +++ b/src/style/CharacterStyle.js @@ -45,7 +45,7 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend(/** @lends Character font: 'sans-serif' }), _owner: TextItem, - _style: '_characterStyle' + _style: 'characterStyle' /** * CharacterStyle objects don't need to be created directly. Just pass an diff --git a/src/style/ParagraphStyle.js b/src/style/ParagraphStyle.js index d0e0a7e7..91a012ad 100644 --- a/src/style/ParagraphStyle.js +++ b/src/style/ParagraphStyle.js @@ -35,7 +35,7 @@ var ParagraphStyle = this.ParagraphStyle = Style.extend(/** @lends ParagraphStyl justification: 'left' }, _owner: TextItem, - _style: '_paragraphStyle' + _style: 'paragraphStyle' /** * ParagraphStyle objects don't need to be created directly. Just pass an diff --git a/src/style/PathStyle.js b/src/style/PathStyle.js index 6531eb2c..fed53a71 100644 --- a/src/style/PathStyle.js +++ b/src/style/PathStyle.js @@ -58,7 +58,7 @@ var PathStyle = this.PathStyle = Style.extend(/** @lends PathStyle# */{ miterLimit: Change.STROKE }, _owner: Item, - _style: '_style' + _style: 'style' // DOCS: why isn't the example code showing up? /** diff --git a/src/style/Style.js b/src/style/Style.js index f432dc62..fe41600d 100644 --- a/src/style/Style.js +++ b/src/style/Style.js @@ -47,9 +47,21 @@ var Style = Item.extend({ // Inject style getters and setters into the 'owning' class, which // redirect calls to the linked style objects through their internal // property on the instances of that class, as defined by _style. - var styleKey = src._style, - flags = src._flags || {}; - src._owner.inject(Base.each(src._defaults, function(value, key) { + var styleKey = '_' + src._style, + stylePart = Base.capitalize(src._style), + flags = src._flags || {}, + owner = {}; + + // Define accessor on owner class for this style: + owner['get' + stylePart] = function() { + return this[styleKey]; + }; + + owner['set' + stylePart] = function(style) { + this[styleKey].initialize(style); + }; + + Base.each(src._defaults, function(value, key) { var isColor = !!key.match(/Color$/), part = Base.capitalize(key), set = 'set' + part, @@ -105,16 +117,16 @@ var Style = Item.extend({ return style; }; // Style-getters and setters for owner class: - // 'this' = the Base.each() side-car = the object that is - // returned from Base.each and injected into _owner above: - this[set] = function(value) { + owner[set] = function(value) { this[styleKey][set](value); return this; }; - this[get] = function() { + owner[get] = function() { return this[styleKey][get](); }; - }, {})); + }); + src._owner.inject(owner); + // Pass on to base() return this.base.apply(this, arguments); } } diff --git a/src/text/TextItem.js b/src/text/TextItem.js index 3f17ba6c..55945e62 100644 --- a/src/text/TextItem.js +++ b/src/text/TextItem.js @@ -94,28 +94,16 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{ * * The character style of the text item. * + * @name TextItem#getCharacterStyle * @type CharacterStyle * @bean */ - getCharacterStyle: function() { - return this._characterStyle; - }, - - setCharacterStyle: function(style) { - this._characterStyle.initialize(style); - }, /** * The paragraph style of the text item. * + * @name TextItem#getParagraphStyle * @type ParagraphStyle * @bean */ - getParagraphStyle: function() { - return this._paragraphStyle; - }, - - setParagraphStyle: function(style) { - this._paragraphStyle.initialize(style); - } });