mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-06 04:42:15 -05:00
Rename Item#setProperties() to hidden #_setProperties() and add public Item#set() to use same functionality from outside.
This commit is contained in:
parent
0fb89bd3e0
commit
ae4e5d4be5
6 changed files with 20 additions and 11 deletions
|
@ -73,7 +73,7 @@ var Group = this.Group = Item.extend(/** @lends Group# */{
|
||||||
// Allow Group to have children and named children
|
// Allow Group to have children and named children
|
||||||
this._children = [];
|
this._children = [];
|
||||||
this._namedChildren = {};
|
this._namedChildren = {};
|
||||||
if (!this.setProperties(arg))
|
if (!this._setProperties(arg))
|
||||||
this.addChildren(Array.isArray(arg) ? arg : arguments);
|
this.addChildren(Array.isArray(arg) ? arg : arguments);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -112,18 +112,27 @@ var Item = this.Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
);
|
);
|
||||||
},
|
},
|
||||||
|
|
||||||
// #setProperties is part of the mechanism for Item constructors which take
|
// #_setProperties is part of the mechanism for Item constructors which take
|
||||||
// one object literal describing all the properties to be set on the created
|
// one object literal describing all the properties to be set on the created
|
||||||
// instance.
|
// instance.
|
||||||
setProperties: function(props) {
|
_setProperties: function(props) {
|
||||||
if (Base.isObject(props)) {
|
if (Base.isObject(props)) {
|
||||||
for (var key in props)
|
this.set(props);
|
||||||
if (props.hasOwnProperty(key))
|
|
||||||
this[key] = props[key];
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Sets all the properties of the passed object literal to their values on
|
||||||
|
* the item it is called on, and returns the item itself.
|
||||||
|
*/
|
||||||
|
set: function(props) {
|
||||||
|
for (var key in props)
|
||||||
|
if (props.hasOwnProperty(key))
|
||||||
|
this[key] = props[key];
|
||||||
|
return this;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Private notifier that is called whenever a change occurs in this item or
|
* Private notifier that is called whenever a change occurs in this item or
|
||||||
* its sub-elements, such as Segments, Curves, PathStyles, etc.
|
* its sub-elements, such as Segments, Curves, PathStyles, etc.
|
||||||
|
|
|
@ -67,7 +67,7 @@ var PlacedSymbol = this.PlacedSymbol = PlacedItem.extend(/** @lends PlacedSymbol
|
||||||
this.base(arg1 !== undefined && Point.read(arguments, 1));
|
this.base(arg1 !== undefined && Point.read(arguments, 1));
|
||||||
// If we can handle setting properties through object literal, we're all
|
// If we can handle setting properties through object literal, we're all
|
||||||
// set. Otherwise we need to set symbol.
|
// set. Otherwise we need to set symbol.
|
||||||
if (!this.setProperties(arg0))
|
if (!this._setProperties(arg0))
|
||||||
this.setSymbol(arg0 instanceof Symbol ? arg0 : new Symbol(arg0));
|
this.setSymbol(arg0 instanceof Symbol ? arg0 : new Symbol(arg0));
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ var Raster = this.Raster = PlacedItem.extend(/** @lends Raster# */{
|
||||||
this.base(arg1 !== undefined && Point.read(arguments, 1));
|
this.base(arg1 !== undefined && Point.read(arguments, 1));
|
||||||
// If we can handle setting properties through object literal, we're all
|
// If we can handle setting properties through object literal, we're all
|
||||||
// set. Otherwise we need to check the type of arg0:
|
// set. Otherwise we need to check the type of arg0:
|
||||||
if (!this.setProperties(arg0)) {
|
if (!this._setProperties(arg0)) {
|
||||||
if (arg0.getContext) {
|
if (arg0.getContext) {
|
||||||
this.setCanvas(arg0);
|
this.setCanvas(arg0);
|
||||||
} else if (typeof arg0 === 'string') {
|
} else if (typeof arg0 === 'string') {
|
||||||
|
|
|
@ -54,7 +54,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
// If it is an array, it can also be a description of a point, so
|
// If it is an array, it can also be a description of a point, so
|
||||||
// check its first entry for object as well.
|
// check its first entry for object as well.
|
||||||
// But first see if segments are directly passed at all. If not, try
|
// But first see if segments are directly passed at all. If not, try
|
||||||
// #setProperties(arg).
|
// _setProperties(arg).
|
||||||
var segments = Array.isArray(arg)
|
var segments = Array.isArray(arg)
|
||||||
? typeof arg[0] === 'object'
|
? typeof arg[0] === 'object'
|
||||||
? arg
|
? arg
|
||||||
|
@ -64,7 +64,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
||||||
: null;
|
: null;
|
||||||
this.setSegments(segments || []);
|
this.setSegments(segments || []);
|
||||||
if (!segments)
|
if (!segments)
|
||||||
this.setProperties(arg);
|
this._setProperties(arg);
|
||||||
},
|
},
|
||||||
|
|
||||||
clone: function() {
|
clone: function() {
|
||||||
|
|
|
@ -49,7 +49,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
||||||
this._content = '';
|
this._content = '';
|
||||||
this._lines = [];
|
this._lines = [];
|
||||||
if (!point)
|
if (!point)
|
||||||
this.setProperties(arg);
|
this._setProperties(arg);
|
||||||
},
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in a new issue