mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-20 22:39:50 -05:00
Clean up method sequence in Item.
This commit is contained in:
parent
75b0fa3596
commit
d535a1f6fc
1 changed files with 49 additions and 50 deletions
|
@ -44,24 +44,6 @@ var Item = this.Item = Base.extend({
|
|||
}
|
||||
return this._id;
|
||||
},
|
||||
|
||||
_removeFromNamed: function() {
|
||||
var children = this._parent._children,
|
||||
namedChildren = this._parent._namedChildren,
|
||||
name = this._name,
|
||||
namedArray = namedChildren[name];
|
||||
if (children[name] = this)
|
||||
delete children[name];
|
||||
namedArray.splice(namedArray.indexOf(this), 1);
|
||||
// If there are any items left in the named array, set
|
||||
// the last of them to be this.parent.children[this.name]
|
||||
if (namedArray.length) {
|
||||
children[name] = namedArray[namedArray.length - 1];
|
||||
} else {
|
||||
// Otherwise delete the empty array
|
||||
delete namedChildren[name];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* The name of the item.
|
||||
|
@ -87,6 +69,47 @@ var Item = this.Item = Base.extend({
|
|||
delete children[name];
|
||||
}
|
||||
},
|
||||
|
||||
_removeFromNamed: function() {
|
||||
var children = this._parent._children,
|
||||
namedChildren = this._parent._namedChildren,
|
||||
name = this._name,
|
||||
namedArray = namedChildren[name];
|
||||
if (children[name] = this)
|
||||
delete children[name];
|
||||
namedArray.splice(namedArray.indexOf(this), 1);
|
||||
// If there are any items left in the named array, set
|
||||
// the last of them to be this.parent.children[this.name]
|
||||
if (namedArray.length) {
|
||||
children[name] = namedArray[namedArray.length - 1];
|
||||
} else {
|
||||
// Otherwise delete the empty array
|
||||
delete namedChildren[name];
|
||||
}
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the item from its parent's children list.
|
||||
*/
|
||||
_removeFromParent: function() {
|
||||
if (this._parent) {
|
||||
if (this._name)
|
||||
this._removeFromNamed();
|
||||
var res = Base.splice(this._parent._children, null, this._index, 1);
|
||||
this._parent = null;
|
||||
return !!res.length;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the item.
|
||||
*/
|
||||
remove: function() {
|
||||
if (this.isSelected())
|
||||
this.setSelected(false);
|
||||
return this._removeFromParent();
|
||||
},
|
||||
|
||||
/**
|
||||
* When passed a project, copies the item to the project,
|
||||
|
@ -245,6 +268,14 @@ var Item = this.Item = Base.extend({
|
|||
this.appendBottom(children[i]);
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the item contains any children items.
|
||||
*
|
||||
* @return true if it has one or more children, false otherwise.
|
||||
*/
|
||||
hasChildren: function() {
|
||||
return this._children && this._children.length > 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Reverses the order of this item's children
|
||||
|
@ -299,38 +330,6 @@ var Item = this.Item = Base.extend({
|
|||
return this._parent && this._parent._children[this._index - 1] || null;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the item from its parent's children list.
|
||||
*/
|
||||
_removeFromParent: function() {
|
||||
if (this._parent) {
|
||||
if (this._name)
|
||||
this._removeFromNamed();
|
||||
var res = Base.splice(this._parent._children, null, this._index, 1);
|
||||
this._parent = null;
|
||||
return !!res.length;
|
||||
}
|
||||
return false;
|
||||
},
|
||||
|
||||
/**
|
||||
* Removes the item.
|
||||
*/
|
||||
remove: function() {
|
||||
if (this.isSelected())
|
||||
this.setSelected(false);
|
||||
return this._removeFromParent();
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks if the item contains any children items.
|
||||
*
|
||||
* @return true if it has one or more children, false otherwise.
|
||||
*/
|
||||
hasChildren: function() {
|
||||
return this._children && this._children.length > 0;
|
||||
},
|
||||
|
||||
/**
|
||||
* Checks whether the item is editable.
|
||||
*
|
||||
|
|
Loading…
Reference in a new issue