mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-03 19:45:44 -05:00
Fix a bug in Item#_removeNamed() for items without parents.
Closes #490.
This commit is contained in:
parent
04a0c995bc
commit
56704b9206
1 changed files with 22 additions and 19 deletions
|
@ -2183,25 +2183,28 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
|||
* Removes the item from its parent's named children list.
|
||||
*/
|
||||
_removeNamed: function() {
|
||||
var children = this._parent._children,
|
||||
namedChildren = this._parent._namedChildren,
|
||||
name = this._name,
|
||||
namedArray = namedChildren[name],
|
||||
index = namedArray ? namedArray.indexOf(this) : -1;
|
||||
if (index == -1)
|
||||
return;
|
||||
// Remove the named reference
|
||||
if (children[name] == this)
|
||||
delete children[name];
|
||||
// Remove this entry
|
||||
namedArray.splice(index, 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];
|
||||
var parent = this._parent;
|
||||
if (parent) {
|
||||
var children = parent._children,
|
||||
namedChildren = parent._namedChildren,
|
||||
name = this._name,
|
||||
namedArray = namedChildren[name],
|
||||
index = namedArray ? namedArray.indexOf(this) : -1;
|
||||
if (index !== -1) {
|
||||
// Remove the named reference
|
||||
if (children[name] == this)
|
||||
delete children[name];
|
||||
// Remove this entry
|
||||
namedArray.splice(index, 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];
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
|
|
Loading…
Reference in a new issue