diff --git a/src/Global.js b/src/Global.js index f775e33d..3877c440 100644 --- a/src/Global.js +++ b/src/Global.js @@ -54,8 +54,35 @@ var Kinetic = {}; * @methodOf Kinetic.Global */ isDragging: function() { - var dd = Kinetic.DD; - return (!dd || dd.isDragging); + var dd = Kinetic.DD; + + // if DD is not included with the build, then + // drag and drop is not even possible + if (!dd) { + return false; + } + // if DD is included with the build + else { + return dd.isDragging; + } + }, + /** + * @method isDragReady returns whether or not a drag and drop operation is ready, but may + * not necessarily have started + * @methodOf Kinetic.Global + */ + isDragReady: function() { + var dd = Kinetic.DD; + + // if DD is not included with the build, then + // drag and drop is not even possible + if (!dd) { + return false; + } + // if DD is included with the build + else { + return !!dd.node; + } }, warn: function(str) { /* diff --git a/src/Stage.js b/src/Stage.js index c0ffbe70..57fb5155 100644 --- a/src/Stage.js +++ b/src/Stage.js @@ -412,10 +412,9 @@ }, _mousedown: function(evt) { this._setPointerPosition(evt); - var dd = Kinetic.DD, - go = Kinetic.Global, - obj = this.getIntersection(this.getPointerPosition()), - shape; + var go = Kinetic.Global, + obj = this.getIntersection(this.getPointerPosition()), + shape; if(obj && obj.shape) { shape = obj.shape; @@ -425,7 +424,7 @@ } //init stage drag and drop - if(this.isDraggable() && !dd.node) { + if(this.isDraggable() && !go.isDragReady()) { this.startDrag(evt); } }, diff --git a/tests/js/functionalTests.js b/tests/js/functionalTests.js index c9c5b009..3e88eeba 100644 --- a/tests/js/functionalTests.js +++ b/tests/js/functionalTests.js @@ -120,6 +120,10 @@ Test.Modules.DD = { }); testDataUrl(layer.toDataURL(), 'drag circle before', 'start data url is incorrect'); + + test(!Kinetic.Global.isDragging(), 'Global isDragging() should be false'); + test(!Kinetic.Global.isDragReady(), 'Global isDragReady()) should be false'); + /* * simulate drag and drop */ @@ -133,11 +137,17 @@ Test.Modules.DD = { //test(!dragMove, 'dragmove event should not have been triggered'); test(!dragEnd, 'dragend event should not have been triggered'); + test(!Kinetic.Global.isDragging(), 'Global isDragging() should be false'); + test(Kinetic.Global.isDragReady(), 'Global isDragReady()) should be true'); + stage._mousemove({ clientX: 100, clientY: 98 + top }); + test(Kinetic.Global.isDragging(), 'Global isDragging() should be true'); + test(Kinetic.Global.isDragReady(), 'Global isDragReady()) should be true'); + test(dragStart, 'dragstart event was not triggered'); //test(dragMove, 'dragmove event was not triggered'); test(!dragEnd, 'dragend event should not have been triggered'); @@ -155,6 +165,10 @@ Test.Modules.DD = { test(events.toString() === 'mouseup,dragend', 'mouseup should occur before dragend'); + + test(!Kinetic.Global.isDragging(), 'Global isDragging() should be false'); + test(!Kinetic.Global.isDragReady(), 'Global isDragReady()) should be false'); + testDataUrl(layer.toDataURL(), 'drag circle after', 'end data url is incorrect'); showHit(layer);