mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-05 20:32:00 -05:00
Move defaults handling fully to Style base class.
This commit is contained in:
parent
f064886c67
commit
55724b0e29
5 changed files with 23 additions and 26 deletions
|
@ -65,14 +65,6 @@ this.Base = Base.inject({
|
||||||
return res;
|
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
|
* 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
|
* each entry keeps a reference to its index in the list in the private
|
||||||
|
|
|
@ -77,6 +77,9 @@ var PathStyle = this.PathStyle = Style.extend(new function() {
|
||||||
? value.clone() : value;
|
? value.clone() : value;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
// Let Style#initialize handle the defaults:
|
||||||
|
if (this._defaults)
|
||||||
|
this.base(style);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,13 @@
|
||||||
* PargraphStyle.
|
* PargraphStyle.
|
||||||
*/
|
*/
|
||||||
var Style = Item.extend({
|
var Style = Item.extend({
|
||||||
|
|
||||||
|
initialize: function(style) {
|
||||||
|
return Base.each(this._defaults || {}, function(value, key) {
|
||||||
|
this[key] = style && style[key] || value;
|
||||||
|
}, this);
|
||||||
|
},
|
||||||
|
|
||||||
statics: {
|
statics: {
|
||||||
create: function(item) {
|
create: function(item) {
|
||||||
var style = new this(this.dont);
|
var style = new this(this.dont);
|
||||||
|
|
|
@ -17,16 +17,20 @@
|
||||||
var CharacterStyle = this.CharacterStyle = PathStyle.extend({
|
var CharacterStyle = this.CharacterStyle = PathStyle.extend({
|
||||||
/** @lends CharacterStyle# */
|
/** @lends CharacterStyle# */
|
||||||
|
|
||||||
|
_defaults: {
|
||||||
|
fontSize: 10,
|
||||||
|
font: 'sans-serif'
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* CharacterStyle objects don't need to be created directly. Just pass an
|
* CharacterStyle objects don't need to be created directly. Just pass an
|
||||||
* object to {@link TextItem#characterStyle}, it will be converted to a
|
* object to {@link TextItem#characterStyle}, it will be converted to a
|
||||||
* CharacterStyle object internally.
|
* CharacterStyle object internally.
|
||||||
*
|
*
|
||||||
* @constructs CharacterStyle
|
* @name CharacterStyle
|
||||||
|
* @constructor
|
||||||
* @param {object} style
|
* @param {object} style
|
||||||
*
|
*
|
||||||
* @constructs CharacterStyle
|
|
||||||
*
|
|
||||||
* @class The CharacterStyle object represents the character style of a text
|
* @class The CharacterStyle object represents the character style of a text
|
||||||
* item ({@link TextItem#characterStyle})
|
* item ({@link TextItem#characterStyle})
|
||||||
*
|
*
|
||||||
|
@ -42,13 +46,6 @@ var CharacterStyle = this.CharacterStyle = PathStyle.extend({
|
||||||
*
|
*
|
||||||
* @extends PathStyle
|
* @extends PathStyle
|
||||||
*/
|
*/
|
||||||
initialize: function(style) {
|
|
||||||
Base.initialize(this, style, {
|
|
||||||
fontSize: 10,
|
|
||||||
font: 'sans-serif'
|
|
||||||
});
|
|
||||||
this.base(style);
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The font of the character style.
|
* The font of the character style.
|
||||||
|
|
|
@ -17,16 +17,19 @@
|
||||||
var ParagraphStyle = this.ParagraphStyle = Style.extend({
|
var ParagraphStyle = this.ParagraphStyle = Style.extend({
|
||||||
/** @lends ParagraphStyle# */
|
/** @lends ParagraphStyle# */
|
||||||
|
|
||||||
|
_defaults: {
|
||||||
|
justification: 'left'
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* ParagraphStyle objects don't need to be created directly. Just pass an
|
* ParagraphStyle objects don't need to be created directly. Just pass an
|
||||||
* object to {@link TextItem#paragraphStyle}, it will be converted to a
|
* object to {@link TextItem#paragraphStyle}, it will be converted to a
|
||||||
* ParagraphStyle object internally.
|
* ParagraphStyle object internally.
|
||||||
*
|
*
|
||||||
* @constructs ParagraphStyle
|
* @name ParagraphStyle
|
||||||
|
* @constructor
|
||||||
* @param {object} style
|
* @param {object} style
|
||||||
*
|
*
|
||||||
* @constructs ParagraphStyle
|
|
||||||
*
|
|
||||||
* @class The ParagraphStyle object represents the paragraph style of a text
|
* @class The ParagraphStyle object represents the paragraph style of a text
|
||||||
* item ({@link TextItem#paragraphStyle}).
|
* item ({@link TextItem#paragraphStyle}).
|
||||||
*
|
*
|
||||||
|
@ -42,11 +45,6 @@ var ParagraphStyle = this.ParagraphStyle = Style.extend({
|
||||||
* text.paragraphStyle.justification = 'center';
|
* text.paragraphStyle.justification = 'center';
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
initialize: function(style) {
|
|
||||||
Base.initialize(this, style, {
|
|
||||||
justification: 'left'
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The justification of the paragraph.
|
* The justification of the paragraph.
|
||||||
|
|
Loading…
Reference in a new issue