Droppable: Added activate and deactivate events.

This commit is contained in:
Scott González 2012-01-29 13:04:40 -05:00
parent 8ebdba7346
commit 74e2828ea0

View File

@ -63,8 +63,12 @@ $.widget( "ui.droppable", {
/** internal **/ /** internal **/
_accept: function( element ) { _start: function( event, ui ) {
return this.options.accept ? element.is( this.options.accept ) : true; if ( this.options.accept && !$( event.target ).is( this.options.accept ) ) {
return false;
}
this._trigger( "activate", event, this._uiHash() );
}, },
_drag: function( event, ui ) { _drag: function( event, ui ) {
@ -89,11 +93,13 @@ $.widget( "ui.droppable", {
} }
}, },
_dragStop: function( event, ui ) { _stop: function( event, ui ) {
if ( this.over ) { if ( this.over ) {
this._trigger( "drop", event, this._uiHash() ); this._trigger( "drop", event, this._uiHash() );
} }
this._trigger( "deactivate", event, this._uiHash() );
this.over = false; this.over = false;
}, },
@ -139,8 +145,7 @@ $.extend( $.ui.droppable, {
_draggableStart: function( event, ui ) { _draggableStart: function( event, ui ) {
var droppable, var droppable,
target = $( event.target ), element = ui.helper || $( event.target );
element = ui.helper || target;
this.draggableProportions = { this.draggableProportions = {
width: element.outerWidth(), width: element.outerWidth(),
@ -149,7 +154,7 @@ $.extend( $.ui.droppable, {
this.active = []; this.active = [];
for ( droppable in droppables ) { for ( droppable in droppables ) {
if ( droppables[ droppable ]._accept( target ) ) { if ( droppables[ droppable ]._start( event, ui ) !== false ) {
this.active.push( droppables[ droppable ] ); this.active.push( droppables[ droppable ] );
} }
} }
@ -163,7 +168,7 @@ $.extend( $.ui.droppable, {
_draggableStop: function( event, ui ) { _draggableStop: function( event, ui ) {
$.each( this.active, function() { $.each( this.active, function() {
this._dragStop( event, ui ); this._stop( event, ui );
}); });
} }
}); });