mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Droppable: Added accept option.
This commit is contained in:
parent
97af9236c2
commit
8ebdba7346
52
ui/jquery.ui.droppable.js
vendored
52
ui/jquery.ui.droppable.js
vendored
@ -20,19 +20,11 @@ var guid = 0,
|
|||||||
(function() {
|
(function() {
|
||||||
var orig = $.ui.draggable.prototype._trigger;
|
var orig = $.ui.draggable.prototype._trigger;
|
||||||
$.ui.draggable.prototype._trigger = function( type, event, ui ) {
|
$.ui.draggable.prototype._trigger = function( type, event, ui ) {
|
||||||
var droppable,
|
var method = "_draggable" + type.substr( 0, 1 ).toUpperCase() + type.substr( 1 ),
|
||||||
method = "_draggable" + type.substr( 0, 1 ).toUpperCase() + type.substr( 1 ),
|
|
||||||
allowed = orig.apply( this, arguments );
|
allowed = orig.apply( this, arguments );
|
||||||
|
|
||||||
if ( allowed ) {
|
if ( allowed && $.ui.droppable[ method ] ) {
|
||||||
if ( $.ui.droppable[ method ] ) {
|
$.ui.droppable[ method ]( event, ui );
|
||||||
$.ui.droppable[ method ]( event, ui );
|
|
||||||
}
|
|
||||||
if ( $.ui.droppable.prototype[ method ] ) {
|
|
||||||
for ( droppable in droppables ) {
|
|
||||||
droppables[ droppable ][ method ]( event, ui );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return allowed;
|
return allowed;
|
||||||
@ -44,7 +36,7 @@ $.widget( "ui.droppable", {
|
|||||||
widgetEventPrefix: "drop",
|
widgetEventPrefix: "drop",
|
||||||
|
|
||||||
options: {
|
options: {
|
||||||
// accept: null,
|
accept: null,
|
||||||
// greedy: false,
|
// greedy: false,
|
||||||
tolerance: "intersect"
|
tolerance: "intersect"
|
||||||
},
|
},
|
||||||
@ -69,9 +61,13 @@ $.widget( "ui.droppable", {
|
|||||||
};
|
};
|
||||||
},
|
},
|
||||||
|
|
||||||
/** draggable integration **/
|
/** internal **/
|
||||||
|
|
||||||
_draggableDrag: function( event, ui ) {
|
_accept: function( element ) {
|
||||||
|
return this.options.accept ? element.is( this.options.accept ) : true;
|
||||||
|
},
|
||||||
|
|
||||||
|
_drag: function( event, ui ) {
|
||||||
var draggableProportions = $.ui.droppable.draggableProportions,
|
var draggableProportions = $.ui.droppable.draggableProportions,
|
||||||
edges = {
|
edges = {
|
||||||
right: this.offset.left + this.proportions.width,
|
right: this.offset.left + this.proportions.width,
|
||||||
@ -93,7 +89,7 @@ $.widget( "ui.droppable", {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
_draggableStop: function( event, ui ) {
|
_dragStop: function( event, ui ) {
|
||||||
if ( this.over ) {
|
if ( this.over ) {
|
||||||
this._trigger( "drop", event, this._uiHash() );
|
this._trigger( "drop", event, this._uiHash() );
|
||||||
}
|
}
|
||||||
@ -101,8 +97,6 @@ $.widget( "ui.droppable", {
|
|||||||
this.over = false;
|
this.over = false;
|
||||||
},
|
},
|
||||||
|
|
||||||
/** internal **/
|
|
||||||
|
|
||||||
// TODO: fill me out
|
// TODO: fill me out
|
||||||
_uiHash: function() {
|
_uiHash: function() {
|
||||||
return {};
|
return {};
|
||||||
@ -115,6 +109,7 @@ $.widget( "ui.droppable", {
|
|||||||
|
|
||||||
$.extend( $.ui.droppable, {
|
$.extend( $.ui.droppable, {
|
||||||
// draggableProportions: width and height of currently dragging draggable
|
// draggableProportions: width and height of currently dragging draggable
|
||||||
|
// active: array of active droppables
|
||||||
|
|
||||||
tolerance: {
|
tolerance: {
|
||||||
// Half of the draggable overlaps the droppable, horizontally and vertically
|
// Half of the draggable overlaps the droppable, horizontally and vertically
|
||||||
@ -143,12 +138,33 @@ $.extend( $.ui.droppable, {
|
|||||||
},
|
},
|
||||||
|
|
||||||
_draggableStart: function( event, ui ) {
|
_draggableStart: function( event, ui ) {
|
||||||
var element = ui.helper || $( event.target );
|
var droppable,
|
||||||
|
target = $( event.target ),
|
||||||
|
element = ui.helper || target;
|
||||||
|
|
||||||
this.draggableProportions = {
|
this.draggableProportions = {
|
||||||
width: element.outerWidth(),
|
width: element.outerWidth(),
|
||||||
height: element.outerHeight()
|
height: element.outerHeight()
|
||||||
};
|
};
|
||||||
|
|
||||||
|
this.active = [];
|
||||||
|
for ( droppable in droppables ) {
|
||||||
|
if ( droppables[ droppable ]._accept( target ) ) {
|
||||||
|
this.active.push( droppables[ droppable ] );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
|
_draggableDrag: function( event, ui ) {
|
||||||
|
$.each( this.active, function() {
|
||||||
|
this._drag( event, ui );
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
|
_draggableStop: function( event, ui ) {
|
||||||
|
$.each( this.active, function() {
|
||||||
|
this._dragStop( event, ui );
|
||||||
|
});
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user