fix bug 169 when removing a node, be sure to also remove the drag and drop reference

This commit is contained in:
Eric Rowell 2012-12-13 00:01:24 -08:00
parent 3fb9576672
commit 5e16b3d7d0
3 changed files with 47 additions and 0 deletions

View File

@ -145,6 +145,7 @@
this.off('mousedown.kinetic'); this.off('mousedown.kinetic');
this.off('touchstart.kinetic'); this.off('touchstart.kinetic');
}; };
/** /**
* get draggable. Alias of getDraggable() * get draggable. Alias of getDraggable()
* @name isDraggable * @name isDraggable

View File

@ -167,6 +167,12 @@
parent.children.splice(this.index, 1); parent.children.splice(this.index, 1);
parent._setChildrenIndices(); parent._setChildrenIndices();
// remove from DD
var dd = Kinetic.DD;
if(dd && dd.node && dd.node._id === this._id) {
delete Kinetic.DD.node;
}
// remove children // remove children
while(this.children && this.children.length > 0) { while(this.children && this.children.length > 0) {
this.children[0].remove(); this.children[0].remove();

View File

@ -1,4 +1,44 @@
Test.Modules.DD = { Test.Modules.DD = {
'remove shape from onclick': function(containerId) {
var stage = new Kinetic.Stage({
container: containerId,
width: 578,
height: 200
});
var top = stage.content.getBoundingClientRect().top;
var layer = new Kinetic.Layer();
var circle = new Kinetic.Circle({
x: stage.getWidth() / 2,
y: stage.getHeight() / 2,
radius: 70,
fill: 'green',
stroke: 'black',
strokeWidth: 4,
name: 'myCircle',
draggable: true
});
layer.add(circle);
stage.add(layer);
circle.on('click', function() {
this.remove();
layer.draw();
});
stage._mousedown({
clientX: 291,
clientY: 112 + top
});
stage._mouseup({
clientX: 291,
clientY: 112 + top
});
},
'test dragstart, dragmove, dragend': function(containerId) { 'test dragstart, dragmove, dragend': function(containerId) {
var stage = new Kinetic.Stage({ var stage = new Kinetic.Stage({
container: containerId, container: containerId,