you can now cancel drag and drop with setDraggable(false) during a drag and drop operation

This commit is contained in:
Eric Rowell
2012-06-19 17:06:31 -07:00
parent 5679b1fb76
commit ce5a8f3209
5 changed files with 102 additions and 14 deletions

View File

@@ -36,12 +36,24 @@ Kinetic.Node = function(config) {
this.setAttrs(config);
// bind events
this.on('draggableChange.kinetic_reserved', function() {
this.on('draggableChange.kinetic', function() {
if(this.attrs.draggable) {
this._listenDrag();
}
else {
// remove event listeners
this._dragCleanup();
/*
* force drag and drop to end
* if this node is currently in
* drag and drop mode
*/
var stage = this.getStage();
var go = Kinetic.GlobalObject;
if(stage && go.drag.node && go.drag.node._id === this._id) {
stage._endDrag();
}
}
});
/*
@@ -734,7 +746,7 @@ Kinetic.Node.prototype = {
this._dragCleanup();
var go = Kinetic.GlobalObject;
var that = this;
this.on('mousedown.initdrag touchstart.initdrag', function(evt) {
this.on('mousedown.kinetic_initdrag touchstart.kinetic_initdrag', function(evt) {
that._initDrag();
});
},
@@ -755,8 +767,8 @@ Kinetic.Node.prototype = {
* remove drag and drop event listener
*/
_dragCleanup: function() {
this.off('mousedown.initdrag');
this.off('touchstart.initdrag');
this.off('mousedown.kinetic_initdrag');
this.off('touchstart.kinetic_initdrag');
},
/**
* handle node event