mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Droppable: Added activeClass backCompat
This commit is contained in:
parent
9d2b81c594
commit
3f6ecfe49f
68
ui/jquery.ui.droppable.js
vendored
68
ui/jquery.ui.droppable.js
vendored
@ -64,17 +64,29 @@ $.widget( "ui.droppable", {
|
||||
/** internal **/
|
||||
|
||||
_start: function( event ) {
|
||||
if ( typeof this.options.accept === "function" ) {
|
||||
if ( this.options.accept.call( this.element, event.target ) !== true ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ( this.options.accept && !$( event.target ).is( this.options.accept ) ) {
|
||||
|
||||
// If draggable is acceptable to this droppable
|
||||
if ( !this._isAcceptable( event.target ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
this._trigger( "activate", event, this._uiHash() );
|
||||
},
|
||||
|
||||
_isAcceptable: function( draggable ) {
|
||||
|
||||
if ( $.isFunction( this.options.accept ) ) {
|
||||
if ( this.options.accept.call( this.element, draggable ) !== true ) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if ( this.options.accept && !$( draggable ).is( this.options.accept ) ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
},
|
||||
|
||||
_drag: function( event, ui ) {
|
||||
var draggableProportions = $.ui.droppable.draggableProportions,
|
||||
@ -197,3 +209,47 @@ $.extend( $.ui.droppable, {
|
||||
|
||||
})( jQuery );
|
||||
|
||||
|
||||
// DEPRECATED
|
||||
if ( $.uiBackCompat !== false ) {
|
||||
|
||||
// Overwriting _setOption to handle multiple backCompats
|
||||
$.widget( "ui.droppable", $.ui.droppable, {
|
||||
|
||||
options: {
|
||||
activeClass: false
|
||||
},
|
||||
|
||||
_create: function() {
|
||||
|
||||
var self = this,
|
||||
added = false;
|
||||
|
||||
this._super();
|
||||
|
||||
// On drag, make sure top does not change so axis is locked
|
||||
$(this.document[0].body).on( "drag", ".ui-draggable", function( event, ui ) {
|
||||
|
||||
if ( !added && self.options.activeClass && self._isAcceptable( event.target ) ) {
|
||||
|
||||
self.element.addClass( self.options.activeClass );
|
||||
added = true;
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
$(this.document[0].body).on( "dragstop", ".ui-draggable", function( event, ui ) {
|
||||
|
||||
if ( added ) {
|
||||
self.element.removeClass( self.options.activeClass );
|
||||
added = false;
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
});
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user