From 2c9ee0252d84709319928c159cbefbc5ba29cdaa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Scott=20Gonz=C3=A1lez?= Date: Sun, 15 Jan 2012 13:35:23 -0500 Subject: [PATCH] Droppable: Only react to drag events if they're not canceled. Fixed pointer intersection. --- ui/jquery.ui.droppable.js | 25 +++++++++++-------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index 761c40567..3d1823ca5 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -18,17 +18,19 @@ var guid = 0, droppables = {}; (function() { - // TODO: we need to react after the event, in case an event handler changes the position - // TODO: don't react if the event is canceled - // TODO: we need access to pointerPosition var orig = $.ui.draggable.prototype._trigger; $.ui.draggable.prototype._trigger = function( type, event, ui ) { var droppable, - method = "_draggable" + type.substr( 0, 1 ).toUpperCase() + type.substr( 1 ); - for ( droppable in droppables ) { - droppables[ droppable ][ method ].call( droppables[ droppable ], event, ui ); + method = "_draggable" + type.substr( 0, 1 ).toUpperCase() + type.substr( 1 ), + allowed = orig.apply( this, arguments ); + + if ( allowed ) { + for ( droppable in droppables ) { + droppables[ droppable ][ method ]( event, ui ); + } } - orig.apply( this, arguments ); + + return allowed; }; })(); @@ -141,14 +143,9 @@ $.ui.droppable.tolerance = { }, // Pointer overlaps droppable - // TODO: this has to use pointerPosition, not event pointer: function( event, edges, ui ) { - var xOverlap = event.pageX >= this.offset.left && - event.pageX <= edges.right, - yOverlap = event.pageY >= this.offset.top && - event.pageY <= edges.bottom; - - return xOverlap && yOverlap; + return ui.pointer.x >= this.offset.left && ui.pointer.x <= edges.right && + ui.pointer.y >= this.offset.top && ui.pointer.y <= edges.bottom; } };