moved dd logic in destroy() from Node to DD namespace. refactored stopDrag logic to correctly handle the event object

This commit is contained in:
Eric Rowell
2013-04-07 10:52:33 -07:00
parent 6f61b07500
commit b6cca6a143
3 changed files with 113 additions and 17 deletions

View File

@@ -40,7 +40,6 @@
},
_endDragBefore: function(evt) {
var dd = Kinetic.DD,
evt = evt || {},
node = dd.node,
nodeType, layer;
@@ -53,17 +52,15 @@
// operation actually started.
if(dd.isDragging) {
dd.isDragging = false;
evt.dragEndNode = node;
if (evt) {
evt.dragEndNode = node;
}
}
delete dd.node;
if (layer) {
layer.draw();
}
else {
node.draw();
}
(layer || node).draw();
}
},
_endDragAfter: function(evt) {
@@ -112,9 +109,10 @@
* @methodOf Kinetic.Node.prototype
*/
Kinetic.Node.prototype.stopDrag = function() {
var dd = Kinetic.DD;
dd._endDragBefore();
dd._endDragAfter();
var dd = Kinetic.DD,
evt = {};
dd._endDragBefore(evt);
dd._endDragAfter(evt);
};
/**
@@ -128,6 +126,20 @@
this._dragChange();
};
var origDestroy = Kinetic.Node.prototype.destroy;
Kinetic.Node.prototype.destroy = function() {
var dd = Kinetic.DD;
// stop DD
if(dd.node && dd.node._id === this._id) {
this.stopDrag();
}
origDestroy.call(this);
};
/**
* determine if node is currently in drag and drop mode
* @name isDragging

View File

@@ -153,11 +153,6 @@
go._removeId(this.getId());
go._removeName(this.getName(), this._id);
// stop DD
if(dd && dd.node && dd.node._id === this._id) {
this._endDrag();
}
// stop transition
if(this.trans) {
this.trans.stop();