mirror of
https://github.com/konvajs/konva.git
synced 2025-04-05 20:48:28 +08:00
parent
cadcb91fbc
commit
74060ce935
@ -60,8 +60,11 @@
|
||||
* @returns {Container}
|
||||
*/
|
||||
add: function(child) {
|
||||
if (child.getParent()) {
|
||||
child.moveTo(this);
|
||||
return;
|
||||
}
|
||||
var children = this.children;
|
||||
|
||||
this._validateAdd(child);
|
||||
child.index = children.length;
|
||||
child.parent = this;
|
||||
|
@ -1352,6 +1352,41 @@ suite('Container', function() {
|
||||
assert.equal(blueGroup.getZIndex(), 1, 'blue group should have zindex 1 after relayering');
|
||||
assert.equal(greenGroup.getZIndex(), 0, 'green group should have zindex 0 after relayering');
|
||||
|
||||
layer.draw();
|
||||
});
|
||||
|
||||
// ======================================================
|
||||
test('add and moveTo should work same way (depend on parent)', function() {
|
||||
var stage = addStage();
|
||||
var layer = new Kinetic.Layer();
|
||||
var greenGroup = new Kinetic.Group();
|
||||
var blueGroup = new Kinetic.Group();
|
||||
|
||||
var bluecircle = new Kinetic.Circle({
|
||||
x: 200,
|
||||
y: stage.getHeight() / 2,
|
||||
radius: 70,
|
||||
fill: 'blue',
|
||||
stroke: 'black',
|
||||
strokeWidth: 4
|
||||
});
|
||||
|
||||
bluecircle.moveTo(blueGroup);
|
||||
|
||||
layer.add(blueGroup);
|
||||
layer.add(greenGroup);
|
||||
stage.add(layer);
|
||||
|
||||
assert.equal(blueGroup.getChildren().length, 1, 'blue group should have only one children');
|
||||
blueGroup.add(bluecircle);
|
||||
assert.equal(blueGroup.getChildren().length, 1, 'blue group should have only one children after adding node twice');
|
||||
|
||||
greenGroup.add(bluecircle);
|
||||
assert.equal(blueGroup.getChildren().length, 0, 'blue group should not have children');
|
||||
assert.equal(greenGroup.getChildren().length, 1, 'green group should have only one children');
|
||||
|
||||
|
||||
|
||||
layer.draw();
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user