mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -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
|
||||
this._children = [];
|
||||
this._namedChildren = {};
|
||||
if (!this.setProperties(arg))
|
||||
if (!this._setProperties(arg))
|
||||
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
|
||||
// instance.
|
||||
setProperties: function(props) {
|
||||
_setProperties: function(props) {
|
||||
if (Base.isObject(props)) {
|
||||
for (var key in props)
|
||||
if (props.hasOwnProperty(key))
|
||||
this[key] = props[key];
|
||||
this.set(props);
|
||||
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
|
||||
* 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));
|
||||
// If we can handle setting properties through object literal, we're all
|
||||
// set. Otherwise we need to set symbol.
|
||||
if (!this.setProperties(arg0))
|
||||
if (!this._setProperties(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));
|
||||
// If we can handle setting properties through object literal, we're all
|
||||
// set. Otherwise we need to check the type of arg0:
|
||||
if (!this.setProperties(arg0)) {
|
||||
if (!this._setProperties(arg0)) {
|
||||
if (arg0.getContext) {
|
||||
this.setCanvas(arg0);
|
||||
} 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
|
||||
// check its first entry for object as well.
|
||||
// But first see if segments are directly passed at all. If not, try
|
||||
// #setProperties(arg).
|
||||
// _setProperties(arg).
|
||||
var segments = Array.isArray(arg)
|
||||
? typeof arg[0] === 'object'
|
||||
? arg
|
||||
|
@ -64,7 +64,7 @@ var Path = this.Path = PathItem.extend(/** @lends Path# */{
|
|||
: null;
|
||||
this.setSegments(segments || []);
|
||||
if (!segments)
|
||||
this.setProperties(arg);
|
||||
this._setProperties(arg);
|
||||
},
|
||||
|
||||
clone: function() {
|
||||
|
|
|
@ -49,7 +49,7 @@ var TextItem = this.TextItem = Item.extend(/** @lends TextItem# */{
|
|||
this._content = '';
|
||||
this._lines = [];
|
||||
if (!point)
|
||||
this.setProperties(arg);
|
||||
this._setProperties(arg);
|
||||
},
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in a new issue