2012-02-27 00:49:51 +00:00
|
|
|
/*!
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Droppable @VERSION
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jqueryui.com
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2022-07-19 07:36:55 +00:00
|
|
|
* Copyright OpenJS Foundation and other contributors
|
2012-08-09 14:13:24 +00:00
|
|
|
* Released under the MIT license.
|
2024-04-26 14:25:34 +00:00
|
|
|
* https://jquery.org/license
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
|
|
|
//>>label: Droppable
|
|
|
|
//>>group: Interactions
|
|
|
|
//>>description: Enables drop targets for draggable elements.
|
2024-04-26 14:25:34 +00:00
|
|
|
//>>docs: https://api.jqueryui.com/droppable/
|
|
|
|
//>>demos: https://jqueryui.com/droppable/
|
2014-10-30 19:55:08 +00:00
|
|
|
|
2015-08-24 12:59:32 +00:00
|
|
|
( function( factory ) {
|
2021-06-06 22:58:12 +00:00
|
|
|
"use strict";
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
if ( typeof define === "function" && define.amd ) {
|
|
|
|
|
|
|
|
// AMD. Register as an anonymous module.
|
2015-08-24 12:59:32 +00:00
|
|
|
define( [
|
2013-07-12 16:40:48 +00:00
|
|
|
"jquery",
|
2015-07-15 02:03:06 +00:00
|
|
|
"./draggable",
|
2015-07-15 02:18:43 +00:00
|
|
|
"./mouse",
|
2015-07-15 02:03:06 +00:00
|
|
|
"../version",
|
|
|
|
"../widget"
|
2013-07-12 16:40:48 +00:00
|
|
|
], factory );
|
|
|
|
} else {
|
|
|
|
|
|
|
|
// Browser globals
|
|
|
|
factory( jQuery );
|
|
|
|
}
|
2021-06-06 22:58:12 +00:00
|
|
|
} )( function( $ ) {
|
|
|
|
"use strict";
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
$.widget( "ui.droppable", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-02-05 03:03:50 +00:00
|
|
|
widgetEventPrefix: "drop",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2012-12-25 17:01:09 +00:00
|
|
|
accept: "*",
|
2010-01-07 03:19:50 +00:00
|
|
|
addClasses: true,
|
|
|
|
greedy: false,
|
2012-12-25 17:01:09 +00:00
|
|
|
scope: "default",
|
2013-01-02 23:27:22 +00:00
|
|
|
tolerance: "intersect",
|
|
|
|
|
2015-08-21 04:10:45 +00:00
|
|
|
// Callbacks
|
2013-01-02 23:27:22 +00:00
|
|
|
activate: null,
|
|
|
|
deactivate: null,
|
|
|
|
drop: null,
|
|
|
|
out: null,
|
|
|
|
over: null
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2010-01-15 18:58:20 +00:00
|
|
|
_create: function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-10 21:03:44 +00:00
|
|
|
var proportions,
|
|
|
|
o = this.options,
|
2012-11-17 19:51:56 +00:00
|
|
|
accept = o.accept;
|
|
|
|
|
|
|
|
this.isover = false;
|
|
|
|
this.isout = true;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2019-12-08 21:23:08 +00:00
|
|
|
this.accept = typeof accept === "function" ? accept : function( d ) {
|
2013-05-24 03:54:17 +00:00
|
|
|
return d.is( accept );
|
2008-07-14 14:21:07 +00:00
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-10 21:03:44 +00:00
|
|
|
this.proportions = function( /* valueToWrite */ ) {
|
|
|
|
if ( arguments.length ) {
|
2015-08-24 12:59:32 +00:00
|
|
|
|
2013-05-10 21:03:44 +00:00
|
|
|
// Store the droppable's proportions
|
|
|
|
proportions = arguments[ 0 ];
|
|
|
|
} else {
|
2015-08-24 12:59:32 +00:00
|
|
|
|
2013-05-10 21:03:44 +00:00
|
|
|
// Retrieve or derive the droppable's proportions
|
|
|
|
return proportions ?
|
|
|
|
proportions :
|
|
|
|
proportions = {
|
|
|
|
width: this.element[ 0 ].offsetWidth,
|
|
|
|
height: this.element[ 0 ].offsetHeight
|
|
|
|
};
|
|
|
|
}
|
|
|
|
};
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-10-29 13:48:51 +00:00
|
|
|
this._addToManager( o.scope );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
if ( o.addClasses ) {
|
|
|
|
this._addClass( "ui-droppable" );
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2013-10-29 13:48:51 +00:00
|
|
|
_addToManager: function( scope ) {
|
2015-08-24 12:59:32 +00:00
|
|
|
|
2013-10-29 13:48:51 +00:00
|
|
|
// Add the reference and positions to the manager
|
|
|
|
$.ui.ddmanager.droppables[ scope ] = $.ui.ddmanager.droppables[ scope ] || [];
|
|
|
|
$.ui.ddmanager.droppables[ scope ].push( this );
|
|
|
|
},
|
2012-11-17 19:51:56 +00:00
|
|
|
|
2013-10-29 13:48:51 +00:00
|
|
|
_splice: function( drop ) {
|
|
|
|
var i = 0;
|
2012-11-17 19:51:56 +00:00
|
|
|
for ( ; i < drop.length; i++ ) {
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( drop[ i ] === this ) {
|
|
|
|
drop.splice( i, 1 );
|
2012-11-17 19:51:56 +00:00
|
|
|
}
|
|
|
|
}
|
2013-10-29 13:48:51 +00:00
|
|
|
},
|
|
|
|
|
|
|
|
_destroy: function() {
|
|
|
|
var drop = $.ui.ddmanager.droppables[ this.options.scope ];
|
|
|
|
|
|
|
|
this._splice( drop );
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
_setOption: function( key, value ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( key === "accept" ) {
|
2019-12-08 21:23:08 +00:00
|
|
|
this.accept = typeof value === "function" ? value : function( d ) {
|
2013-05-24 03:54:17 +00:00
|
|
|
return d.is( value );
|
2008-11-21 04:01:33 +00:00
|
|
|
};
|
2013-10-29 13:48:51 +00:00
|
|
|
} else if ( key === "scope" ) {
|
|
|
|
var drop = $.ui.ddmanager.droppables[ this.options.scope ];
|
|
|
|
|
|
|
|
this._splice( drop );
|
|
|
|
this._addToManager( value );
|
2008-11-21 04:01:33 +00:00
|
|
|
}
|
2013-10-29 13:48:51 +00:00
|
|
|
|
2013-03-14 23:08:21 +00:00
|
|
|
this._super( key, value );
|
2008-11-21 04:01:33 +00:00
|
|
|
},
|
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
_activate: function( event ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
var draggable = $.ui.ddmanager.current;
|
2015-01-01 17:11:06 +00:00
|
|
|
|
|
|
|
this._addActiveClass();
|
2015-08-24 12:59:32 +00:00
|
|
|
if ( draggable ) {
|
2013-05-24 03:54:17 +00:00
|
|
|
this._trigger( "activate", event, this.ui( draggable ) );
|
2012-11-17 19:51:56 +00:00
|
|
|
}
|
2008-11-21 04:01:33 +00:00
|
|
|
},
|
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
_deactivate: function( event ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
var draggable = $.ui.ddmanager.current;
|
2015-01-01 17:11:06 +00:00
|
|
|
|
|
|
|
this._removeActiveClass();
|
2015-08-24 12:59:32 +00:00
|
|
|
if ( draggable ) {
|
2013-05-24 03:54:17 +00:00
|
|
|
this._trigger( "deactivate", event, this.ui( draggable ) );
|
2012-11-17 19:51:56 +00:00
|
|
|
}
|
2008-11-21 04:01:33 +00:00
|
|
|
},
|
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
_over: function( event ) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var draggable = $.ui.ddmanager.current;
|
2012-11-17 19:51:56 +00:00
|
|
|
|
|
|
|
// Bail if draggable and droppable are same element
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( !draggable || ( draggable.currentItem ||
|
|
|
|
draggable.element )[ 0 ] === this.element[ 0 ] ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem ||
|
|
|
|
draggable.element ) ) ) {
|
2015-01-01 17:11:06 +00:00
|
|
|
this._addHoverClass();
|
2013-05-24 03:54:17 +00:00
|
|
|
this._trigger( "over", event, this.ui( draggable ) );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
_out: function( event ) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var draggable = $.ui.ddmanager.current;
|
2012-11-17 19:51:56 +00:00
|
|
|
|
|
|
|
// Bail if draggable and droppable are same element
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( !draggable || ( draggable.currentItem ||
|
|
|
|
draggable.element )[ 0 ] === this.element[ 0 ] ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem ||
|
|
|
|
draggable.element ) ) ) {
|
2015-01-01 17:11:06 +00:00
|
|
|
this._removeHoverClass();
|
2013-05-24 03:54:17 +00:00
|
|
|
this._trigger( "out", event, this.ui( draggable ) );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
_drop: function( event, custom ) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2012-11-17 19:51:56 +00:00
|
|
|
var draggable = custom || $.ui.ddmanager.current,
|
|
|
|
childrenIntersection = false;
|
|
|
|
|
|
|
|
// Bail if draggable and droppable are same element
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( !draggable || ( draggable.currentItem ||
|
|
|
|
draggable.element )[ 0 ] === this.element[ 0 ] ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
this.element
|
|
|
|
.find( ":data(ui-droppable)" )
|
|
|
|
.not( ".ui-draggable-dragging" )
|
|
|
|
.each( function() {
|
|
|
|
var inst = $( this ).droppable( "instance" );
|
|
|
|
if (
|
|
|
|
inst.options.greedy &&
|
|
|
|
!inst.options.disabled &&
|
|
|
|
inst.options.scope === draggable.options.scope &&
|
|
|
|
inst.accept.call(
|
|
|
|
inst.element[ 0 ], ( draggable.currentItem || draggable.element )
|
|
|
|
) &&
|
2016-10-01 22:47:36 +00:00
|
|
|
$.ui.intersect(
|
2016-03-31 03:15:29 +00:00
|
|
|
draggable,
|
|
|
|
$.extend( inst, { offset: inst.element.offset() } ),
|
|
|
|
inst.options.tolerance, event
|
|
|
|
)
|
|
|
|
) {
|
|
|
|
childrenIntersection = true;
|
2021-06-06 22:58:12 +00:00
|
|
|
return false;
|
|
|
|
}
|
2016-03-31 03:15:29 +00:00
|
|
|
} );
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( childrenIntersection ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
return false;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( this.accept.call( this.element[ 0 ],
|
|
|
|
( draggable.currentItem || draggable.element ) ) ) {
|
2015-01-01 17:11:06 +00:00
|
|
|
this._removeActiveClass();
|
|
|
|
this._removeHoverClass();
|
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
this._trigger( "drop", event, this.ui( draggable ) );
|
2008-09-18 09:51:50 +00:00
|
|
|
return this.element;
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
return false;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
ui: function( c ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
return {
|
2013-05-24 03:54:17 +00:00
|
|
|
draggable: ( c.currentItem || c.element ),
|
2008-11-21 04:01:33 +00:00
|
|
|
helper: c.helper,
|
|
|
|
position: c.position,
|
2009-01-29 12:35:38 +00:00
|
|
|
offset: c.positionAbs
|
2008-11-21 04:01:33 +00:00
|
|
|
};
|
2015-01-01 17:11:06 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2015-01-01 17:11:06 +00:00
|
|
|
// Extension points just to make backcompat sane and avoid duplicating logic
|
2021-08-26 11:36:06 +00:00
|
|
|
// TODO: Remove in 1.14 along with call to it below
|
2015-01-01 17:11:06 +00:00
|
|
|
_addHoverClass: function() {
|
|
|
|
this._addClass( "ui-droppable-hover" );
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeHoverClass: function() {
|
|
|
|
this._removeClass( "ui-droppable-hover" );
|
|
|
|
},
|
|
|
|
|
|
|
|
_addActiveClass: function() {
|
|
|
|
this._addClass( "ui-droppable-active" );
|
|
|
|
},
|
|
|
|
|
|
|
|
_removeActiveClass: function() {
|
|
|
|
this._removeClass( "ui-droppable-active" );
|
|
|
|
}
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2016-10-01 22:47:36 +00:00
|
|
|
$.ui.intersect = ( function() {
|
2013-09-17 13:33:01 +00:00
|
|
|
function isOverAxis( x, reference, size ) {
|
|
|
|
return ( x >= reference ) && ( x < ( reference + size ) );
|
2012-11-17 19:51:56 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-21 14:19:14 +00:00
|
|
|
return function( draggable, droppable, toleranceMode, event ) {
|
2013-09-17 13:33:01 +00:00
|
|
|
|
|
|
|
if ( !droppable.offset ) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
var x1 = ( draggable.positionAbs ||
|
|
|
|
draggable.position.absolute ).left + draggable.margins.left,
|
|
|
|
y1 = ( draggable.positionAbs ||
|
|
|
|
draggable.position.absolute ).top + draggable.margins.top,
|
2013-09-17 13:33:01 +00:00
|
|
|
x2 = x1 + draggable.helperProportions.width,
|
|
|
|
y2 = y1 + draggable.helperProportions.height,
|
|
|
|
l = droppable.offset.left,
|
|
|
|
t = droppable.offset.top,
|
|
|
|
r = l + droppable.proportions().width,
|
|
|
|
b = t + droppable.proportions().height;
|
|
|
|
|
|
|
|
switch ( toleranceMode ) {
|
2012-12-25 17:01:09 +00:00
|
|
|
case "fit":
|
2013-05-24 03:54:17 +00:00
|
|
|
return ( l <= x1 && x2 <= r && t <= y1 && y2 <= b );
|
2012-12-25 17:01:09 +00:00
|
|
|
case "intersect":
|
2013-05-24 03:54:17 +00:00
|
|
|
return ( l < x1 + ( draggable.helperProportions.width / 2 ) && // Right Half
|
|
|
|
x2 - ( draggable.helperProportions.width / 2 ) < r && // Left Half
|
|
|
|
t < y1 + ( draggable.helperProportions.height / 2 ) && // Bottom Half
|
|
|
|
y2 - ( draggable.helperProportions.height / 2 ) < b ); // Top Half
|
2012-12-25 17:01:09 +00:00
|
|
|
case "pointer":
|
2016-03-31 03:15:29 +00:00
|
|
|
return isOverAxis( event.pageY, t, droppable.proportions().height ) &&
|
|
|
|
isOverAxis( event.pageX, l, droppable.proportions().width );
|
2012-12-25 17:01:09 +00:00
|
|
|
case "touch":
|
2008-06-04 02:34:33 +00:00
|
|
|
return (
|
2013-05-24 03:54:17 +00:00
|
|
|
( y1 >= t && y1 <= b ) || // Top edge touching
|
|
|
|
( y2 >= t && y2 <= b ) || // Bottom edge touching
|
|
|
|
( y1 < t && y2 > b ) // Surrounded vertically
|
2012-10-31 02:19:49 +00:00
|
|
|
) && (
|
2013-05-24 03:54:17 +00:00
|
|
|
( x1 >= l && x1 <= r ) || // Left edge touching
|
|
|
|
( x2 >= l && x2 <= r ) || // Right edge touching
|
|
|
|
( x1 < l && x2 > r ) // Surrounded horizontally
|
2012-10-31 02:19:49 +00:00
|
|
|
);
|
2008-06-04 02:34:33 +00:00
|
|
|
default:
|
|
|
|
return false;
|
|
|
|
}
|
2013-09-17 13:33:01 +00:00
|
|
|
};
|
2015-08-24 12:59:32 +00:00
|
|
|
} )();
|
2008-06-04 02:34:33 +00:00
|
|
|
|
|
|
|
/*
|
|
|
|
This manager tracks offsets of draggables and droppables
|
|
|
|
*/
|
|
|
|
$.ui.ddmanager = {
|
|
|
|
current: null,
|
2012-12-25 17:01:09 +00:00
|
|
|
droppables: { "default": [] },
|
2013-05-24 03:54:17 +00:00
|
|
|
prepareOffsets: function( t, event ) {
|
2009-01-16 02:09:45 +00:00
|
|
|
|
2012-11-17 19:51:56 +00:00
|
|
|
var i, j,
|
2013-05-24 03:54:17 +00:00
|
|
|
m = $.ui.ddmanager.droppables[ t.options.scope ] || [],
|
2012-11-17 19:51:56 +00:00
|
|
|
type = event ? event.type : null, // workaround for #2317
|
2013-05-24 03:54:17 +00:00
|
|
|
list = ( t.currentItem || t.element ).find( ":data(ui-droppable)" ).addBack();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
droppablesLoop: for ( i = 0; i < m.length; i++ ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
// No disabled and non-accepted
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( m[ i ].options.disabled || ( t && !m[ i ].accept.call( m[ i ].element[ 0 ],
|
|
|
|
( t.currentItem || t.element ) ) ) ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2012-10-31 02:19:49 +00:00
|
|
|
// Filter out elements in the current dragged item
|
2013-10-16 18:43:09 +00:00
|
|
|
for ( j = 0; j < list.length; j++ ) {
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( list[ j ] === m[ i ].element[ 0 ] ) {
|
|
|
|
m[ i ].proportions().height = 0;
|
2012-10-31 02:19:49 +00:00
|
|
|
continue droppablesLoop;
|
|
|
|
}
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
m[ i ].visible = m[ i ].element.css( "display" ) !== "none";
|
|
|
|
if ( !m[ i ].visible ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
continue;
|
|
|
|
}
|
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
// Activate the droppable if used directly from draggables
|
|
|
|
if ( type === "mousedown" ) {
|
|
|
|
m[ i ]._activate.call( m[ i ], event );
|
2012-11-17 19:51:56 +00:00
|
|
|
}
|
2011-03-11 14:37:52 +00:00
|
|
|
|
2013-05-10 21:03:44 +00:00
|
|
|
m[ i ].offset = m[ i ].element.offset();
|
2016-03-31 03:15:29 +00:00
|
|
|
m[ i ].proportions( {
|
|
|
|
width: m[ i ].element[ 0 ].offsetWidth,
|
|
|
|
height: m[ i ].element[ 0 ].offsetHeight
|
|
|
|
} );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2013-05-24 03:54:17 +00:00
|
|
|
drop: function( draggable, event ) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
var dropped = false;
|
2015-08-24 12:59:32 +00:00
|
|
|
|
2013-02-24 05:55:29 +00:00
|
|
|
// Create a copy of the droppables in case the list changes during the drop (#9116)
|
2013-05-24 03:54:17 +00:00
|
|
|
$.each( ( $.ui.ddmanager.droppables[ draggable.options.scope ] || [] ).slice(), function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( !this.options ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( !this.options.disabled && this.visible &&
|
2016-10-01 22:47:36 +00:00
|
|
|
$.ui.intersect( draggable, this, this.options.tolerance, event ) ) {
|
2013-05-24 03:54:17 +00:00
|
|
|
dropped = this._drop.call( this, event ) || dropped;
|
2012-11-17 19:51:56 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
if ( !this.options.disabled && this.visible && this.accept.call( this.element[ 0 ],
|
|
|
|
( draggable.currentItem || draggable.element ) ) ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
this.isout = true;
|
|
|
|
this.isover = false;
|
2013-05-24 03:54:17 +00:00
|
|
|
this._deactivate.call( this, event );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2008-06-04 02:34:33 +00:00
|
|
|
return dropped;
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2011-05-27 17:01:42 +00:00
|
|
|
dragStart: function( draggable, event ) {
|
2015-08-24 12:59:32 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
// Listen for scrolling so that if the dragging causes scrolling the position of the
|
|
|
|
// droppables can be recalculated (see #5003)
|
2015-05-14 01:58:16 +00:00
|
|
|
draggable.element.parentsUntil( "body" ).on( "scroll.droppable", function() {
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( !draggable.options.refreshPositions ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
$.ui.ddmanager.prepareOffsets( draggable, event );
|
|
|
|
}
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2011-05-27 17:01:42 +00:00
|
|
|
},
|
2013-05-24 03:54:17 +00:00
|
|
|
drag: function( draggable, event ) {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
// If you have a highly dynamic page, you might try this option. It renders positions
|
|
|
|
// every time you move the mouse.
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( draggable.options.refreshPositions ) {
|
|
|
|
$.ui.ddmanager.prepareOffsets( draggable, event );
|
2012-11-17 19:51:56 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
// Run through all droppables and check their positions based on specific tolerance options
|
|
|
|
$.each( $.ui.ddmanager.droppables[ draggable.options.scope ] || [], function() {
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( this.options.disabled || this.greedyChild || !this.visible ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2012-11-17 19:51:56 +00:00
|
|
|
var parentInstance, scope, parent,
|
2016-10-01 22:47:36 +00:00
|
|
|
intersects = $.ui.intersect( draggable, this, this.options.tolerance, event ),
|
2016-03-31 03:15:29 +00:00
|
|
|
c = !intersects && this.isover ?
|
|
|
|
"isout" :
|
|
|
|
( intersects && !this.isover ? "isover" : null );
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( !c ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
return;
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( this.options.greedy ) {
|
2015-08-24 12:59:32 +00:00
|
|
|
|
2012-08-27 18:37:04 +00:00
|
|
|
// find droppable parents with same scope
|
2012-11-17 19:51:56 +00:00
|
|
|
scope = this.options.scope;
|
2015-08-24 12:59:32 +00:00
|
|
|
parent = this.element.parents( ":data(ui-droppable)" ).filter( function() {
|
2013-05-24 03:54:17 +00:00
|
|
|
return $( this ).droppable( "instance" ).options.scope === scope;
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2012-08-27 18:37:04 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( parent.length ) {
|
2013-03-19 15:53:35 +00:00
|
|
|
parentInstance = $( parent[ 0 ] ).droppable( "instance" );
|
2013-05-24 03:54:17 +00:00
|
|
|
parentInstance.greedyChild = ( c === "isover" );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-21 04:10:45 +00:00
|
|
|
// We just moved into a greedy child
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( parentInstance && c === "isover" ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
parentInstance.isover = false;
|
|
|
|
parentInstance.isout = true;
|
2013-05-24 03:54:17 +00:00
|
|
|
parentInstance._out.call( parentInstance, event );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2013-05-24 03:54:17 +00:00
|
|
|
this[ c ] = true;
|
2015-08-24 12:59:32 +00:00
|
|
|
this[ c === "isout" ? "isover" : "isout" ] = false;
|
|
|
|
this[ c === "isover" ? "_over" : "_out" ].call( this, event );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2015-08-21 04:10:45 +00:00
|
|
|
// We just moved out of a greedy child
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( parentInstance && c === "isout" ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
parentInstance.isout = false;
|
|
|
|
parentInstance.isover = true;
|
2013-05-24 03:54:17 +00:00
|
|
|
parentInstance._over.call( parentInstance, event );
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-05-27 17:01:42 +00:00
|
|
|
},
|
|
|
|
dragStop: function( draggable, event ) {
|
2015-05-14 01:58:16 +00:00
|
|
|
draggable.element.parentsUntil( "body" ).off( "scroll.droppable" );
|
2015-08-24 12:59:32 +00:00
|
|
|
|
2016-03-31 03:15:29 +00:00
|
|
|
// Call prepareOffsets one final time since IE does not fire return scroll events when
|
|
|
|
// overflow was caused by drag (see #5003)
|
2013-05-24 03:54:17 +00:00
|
|
|
if ( !draggable.options.refreshPositions ) {
|
2012-11-17 19:51:56 +00:00
|
|
|
$.ui.ddmanager.prepareOffsets( draggable, event );
|
|
|
|
}
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2015-01-01 17:11:06 +00:00
|
|
|
// DEPRECATED
|
|
|
|
// TODO: switch return back to widget declaration at top of file when this is removed
|
2024-05-13 16:11:57 +00:00
|
|
|
if ( $.uiBackCompat === true ) {
|
2015-01-01 17:11:06 +00:00
|
|
|
|
|
|
|
// Backcompat for activeClass and hoverClass options
|
|
|
|
$.widget( "ui.droppable", $.ui.droppable, {
|
|
|
|
options: {
|
|
|
|
hoverClass: false,
|
|
|
|
activeClass: false
|
|
|
|
},
|
|
|
|
_addActiveClass: function() {
|
|
|
|
this._super();
|
|
|
|
if ( this.options.activeClass ) {
|
|
|
|
this.element.addClass( this.options.activeClass );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_removeActiveClass: function() {
|
|
|
|
this._super();
|
|
|
|
if ( this.options.activeClass ) {
|
|
|
|
this.element.removeClass( this.options.activeClass );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_addHoverClass: function() {
|
|
|
|
this._super();
|
|
|
|
if ( this.options.hoverClass ) {
|
|
|
|
this.element.addClass( this.options.hoverClass );
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_removeHoverClass: function() {
|
|
|
|
this._super();
|
|
|
|
if ( this.options.hoverClass ) {
|
|
|
|
this.element.removeClass( this.options.hoverClass );
|
|
|
|
}
|
|
|
|
}
|
2015-08-24 12:59:32 +00:00
|
|
|
} );
|
2015-01-01 17:11:06 +00:00
|
|
|
}
|
|
|
|
|
2013-07-12 16:40:48 +00:00
|
|
|
return $.ui.droppable;
|
|
|
|
|
2021-06-06 22:58:12 +00:00
|
|
|
} );
|