mirror of
https://github.com/scratchfoundation/paper.js.git
synced 2025-01-01 02:38:43 -05:00
parent
91539e6bc5
commit
c87ce4de4c
2 changed files with 36 additions and 0 deletions
|
@ -2244,6 +2244,19 @@ var Item = Base.extend(Callback, /** @lends Item# */{
|
||||||
return this._remove(true, true);
|
return this._remove(true, true);
|
||||||
},
|
},
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Replaces this item with the provided new item which will takes its place
|
||||||
|
* in the project hierarchy instead.
|
||||||
|
*
|
||||||
|
* @return {Boolean} {@true if the item was replaced}
|
||||||
|
*/
|
||||||
|
replaceWith: function(item) {
|
||||||
|
var ok = item && item.insertBelow(this);
|
||||||
|
if (ok)
|
||||||
|
this.remove();
|
||||||
|
return ok;
|
||||||
|
},
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Removes all of the item's {@link #children} (if any).
|
* Removes all of the item's {@link #children} (if any).
|
||||||
*
|
*
|
||||||
|
|
|
@ -183,6 +183,29 @@ test('item.nextSibling / item.previousSibling', function() {
|
||||||
}, true);
|
}, true);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test('item.replaceWith(other)', function() {
|
||||||
|
var project = paper.project;
|
||||||
|
var path = new Path();
|
||||||
|
var secondPath = new Path();
|
||||||
|
var thirdPath = new Path();
|
||||||
|
equals(function() {
|
||||||
|
return project.activeLayer.children.length;
|
||||||
|
}, 3);
|
||||||
|
path.replaceWith(secondPath);
|
||||||
|
equals(function() {
|
||||||
|
return project.activeLayer.children.length;
|
||||||
|
}, 2);
|
||||||
|
equals(function() {
|
||||||
|
return path.parent == null;
|
||||||
|
}, true);
|
||||||
|
equals(function() {
|
||||||
|
return secondPath.previousSibling == null;
|
||||||
|
}, true);
|
||||||
|
equals(function() {
|
||||||
|
return secondPath.nextSibling == thirdPath;
|
||||||
|
}, true);
|
||||||
|
});
|
||||||
|
|
||||||
test('item.insertChild(0, child)', function() {
|
test('item.insertChild(0, child)', function() {
|
||||||
var project = paper.project;
|
var project = paper.project;
|
||||||
var path = new Path();
|
var path = new Path();
|
||||||
|
|
Loading…
Reference in a new issue