From e8e7847a4113b849f2dffa7f29b599d65db96094 Mon Sep 17 00:00:00 2001 From: Dave Stein Date: Sun, 13 Nov 2011 17:42:05 -0500 Subject: [PATCH] Droppable: over, out, and drop callbacks working --- ui/jquery.ui.droppable.js | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index 5cec18b6c..5f72cdf0d 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -29,6 +29,7 @@ $.widget("ui.droppable", { }, // draggableProportions: width and height of currently dragging draggable + // over: whether or not a draggable is currently over droppable // proportions: width and height of droppable _create: function() { @@ -42,6 +43,10 @@ $.widget("ui.droppable", { // TODO: Use $.Callbacks or .on from 1.7 $('*').live( "drag", $.proxy( this._drag, this ) ); $('*').live( "dragstart", $.proxy( this._dragStart, this ) ); + + this._bind( this.document, { + mouseup: "_mouseUp" + }); }, @@ -59,9 +64,15 @@ $.widget("ui.droppable", { xOverlap = ( draggableRightEdge >= this.offset.left && ui.offset.left <= rightEdge ), yOverlap = ( draggableBottomEdge >= this.offset.top && ui.offset.top <= bottomEdge ); + if ( xOverlap && yOverlap ) { - // TODO: properly fill out uiHash - this._trigger( "over", event, {} ); + this._trigger( "over", event, this._uiHash() ); + this.over = true; + } + else if ( this.over ) { + this.over = false; + this._trigger( "out", event, this._uiHash() ); + } break; @@ -77,11 +88,29 @@ $.widget("ui.droppable", { _dragStart: function( event, ui ) { var draggable = $( event.target ); - + + // TODO: Possibly move into draggable hash, so if there are multiple droppables, it's not recalculating all the time this.draggableProportions = { width: draggable[0].offsetWidth, height: draggable[0].offsetHeight }; + }, + + _mouseUp: function( event ) { + + if ( this.over ) { + this._trigger( "drop", event, this._uiHash() ); + } + + this.over = false; + + }, + + // TODO: fill me out + _uiHash: function() { + + return {}; + }