diff --git a/src/core/Base.js b/src/core/Base.js index dfd684fe..31668c57 100644 --- a/src/core/Base.js +++ b/src/core/Base.js @@ -65,14 +65,6 @@ this.Base = Base.inject({ return res; }, - initialize: function(object, values, defaults) { - if (!values) - values = defaults; - return Base.each(defaults, function(value, key) { - this[key] = values[key] || value; - }, object); - }, - /** * Utility function for adding and removing items from a list of which * each entry keeps a reference to its index in the list in the private diff --git a/src/item/PathStyle.js b/src/item/PathStyle.js index ff06150f..e783218d 100644 --- a/src/item/PathStyle.js +++ b/src/item/PathStyle.js @@ -77,6 +77,9 @@ var PathStyle = this.PathStyle = Style.extend(new function() { ? value.clone() : value; } } + // Let Style#initialize handle the defaults: + if (this._defaults) + this.base(style); } }; diff --git a/src/item/Style.js b/src/item/Style.js index 03373b05..687140f6 100644 --- a/src/item/Style.js +++ b/src/item/Style.js @@ -19,6 +19,13 @@ * PargraphStyle. */ var Style = Item.extend({ + + initialize: function(style) { + return Base.each(this._defaults || {}, function(value, key) { + this[key] = style && style[key] || value; + }, this); + }, + statics: { create: function(item) { var style = new this(this.dont); diff --git a/src/text/CharacterStyle.js b/src/text/CharacterStyle.js index 704f3bdb..69a4e41f 100644 --- a/src/text/CharacterStyle.js +++ b/src/text/CharacterStyle.js @@ -17,16 +17,20 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({ /** @lends CharacterStyle# */ + _defaults: { + fontSize: 10, + font: 'sans-serif' + }, + /** * CharacterStyle objects don't need to be created directly. Just pass an * object to {@link TextItem#characterStyle}, it will be converted to a * CharacterStyle object internally. * - * @constructs CharacterStyle + * @name CharacterStyle + * @constructor * @param {object} style * - * @constructs CharacterStyle - * * @class The CharacterStyle object represents the character style of a text * item ({@link TextItem#characterStyle}) * @@ -42,13 +46,6 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({ * * @extends PathStyle */ - initialize: function(style) { - Base.initialize(this, style, { - fontSize: 10, - font: 'sans-serif' - }); - this.base(style); - } /** * The font of the character style. diff --git a/src/text/ParagraphStyle.js b/src/text/ParagraphStyle.js index 09cedcab..7d38e41c 100644 --- a/src/text/ParagraphStyle.js +++ b/src/text/ParagraphStyle.js @@ -17,16 +17,19 @@ var ParagraphStyle = this.ParagraphStyle = Style.extend({ /** @lends ParagraphStyle# */ + _defaults: { + justification: 'left' + }, + /** * ParagraphStyle objects don't need to be created directly. Just pass an * object to {@link TextItem#paragraphStyle}, it will be converted to a * ParagraphStyle object internally. * - * @constructs ParagraphStyle + * @name ParagraphStyle + * @constructor * @param {object} style * - * @constructs ParagraphStyle - * * @class The ParagraphStyle object represents the paragraph style of a text * item ({@link TextItem#paragraphStyle}). * @@ -42,11 +45,6 @@ var ParagraphStyle = this.ParagraphStyle = Style.extend({ * text.paragraphStyle.justification = 'center'; * */ - initialize: function(style) { - Base.initialize(this, style, { - justification: 'left' - }); - } /** * The justification of the paragraph.