1 /*! |
1 /*! |
2 * jQuery UI Droppable 1.13.1 |
2 * jQuery UI Droppable 1.13.3 |
3 * http://jqueryui.com |
3 * https://jqueryui.com |
4 * |
4 * |
5 * Copyright jQuery Foundation and other contributors |
5 * Copyright OpenJS Foundation and other contributors |
6 * Released under the MIT license. |
6 * Released under the MIT license. |
7 * http://jquery.org/license |
7 * https://jquery.org/license |
8 */ |
8 */ |
9 |
9 |
10 //>>label: Droppable |
10 //>>label: Droppable |
11 //>>group: Interactions |
11 //>>group: Interactions |
12 //>>description: Enables drop targets for draggable elements. |
12 //>>description: Enables drop targets for draggable elements. |
13 //>>docs: http://api.jqueryui.com/droppable/ |
13 //>>docs: https://api.jqueryui.com/droppable/ |
14 //>>demos: http://jqueryui.com/droppable/ |
14 //>>demos: https://jqueryui.com/droppable/ |
15 |
15 |
16 ( function( factory ) { |
16 ( function( factory ) { |
17 "use strict"; |
17 "use strict"; |
18 |
18 |
19 if ( typeof define === "function" && define.amd ) { |
19 if ( typeof define === "function" && define.amd ) { |
148 |
149 |
149 var draggable = $.ui.ddmanager.current; |
150 var draggable = $.ui.ddmanager.current; |
150 |
151 |
151 // Bail if draggable and droppable are same element |
152 // Bail if draggable and droppable are same element |
152 if ( !draggable || ( draggable.currentItem || |
153 if ( !draggable || ( draggable.currentItem || |
153 draggable.element )[ 0 ] === this.element[ 0 ] ) { |
154 draggable.element )[ 0 ] === this.element[ 0 ] ) { |
154 return; |
155 return; |
155 } |
156 } |
156 |
157 |
157 if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem || |
158 if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem || |
158 draggable.element ) ) ) { |
159 draggable.element ) ) ) { |
159 this._addHoverClass(); |
160 this._addHoverClass(); |
160 this._trigger( "over", event, this.ui( draggable ) ); |
161 this._trigger( "over", event, this.ui( draggable ) ); |
161 } |
162 } |
162 |
163 |
163 }, |
164 }, |
166 |
167 |
167 var draggable = $.ui.ddmanager.current; |
168 var draggable = $.ui.ddmanager.current; |
168 |
169 |
169 // Bail if draggable and droppable are same element |
170 // Bail if draggable and droppable are same element |
170 if ( !draggable || ( draggable.currentItem || |
171 if ( !draggable || ( draggable.currentItem || |
171 draggable.element )[ 0 ] === this.element[ 0 ] ) { |
172 draggable.element )[ 0 ] === this.element[ 0 ] ) { |
172 return; |
173 return; |
173 } |
174 } |
174 |
175 |
175 if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem || |
176 if ( this.accept.call( this.element[ 0 ], ( draggable.currentItem || |
176 draggable.element ) ) ) { |
177 draggable.element ) ) ) { |
177 this._removeHoverClass(); |
178 this._removeHoverClass(); |
178 this._trigger( "out", event, this.ui( draggable ) ); |
179 this._trigger( "out", event, this.ui( draggable ) ); |
179 } |
180 } |
180 |
181 |
181 }, |
182 }, |
185 var draggable = custom || $.ui.ddmanager.current, |
186 var draggable = custom || $.ui.ddmanager.current, |
186 childrenIntersection = false; |
187 childrenIntersection = false; |
187 |
188 |
188 // Bail if draggable and droppable are same element |
189 // Bail if draggable and droppable are same element |
189 if ( !draggable || ( draggable.currentItem || |
190 if ( !draggable || ( draggable.currentItem || |
190 draggable.element )[ 0 ] === this.element[ 0 ] ) { |
191 draggable.element )[ 0 ] === this.element[ 0 ] ) { |
191 return false; |
192 return false; |
192 } |
193 } |
193 |
194 |
194 this.element |
195 this.element |
195 .find( ":data(ui-droppable)" ) |
196 .find( ":data(ui-droppable)" ) |
216 if ( childrenIntersection ) { |
217 if ( childrenIntersection ) { |
217 return false; |
218 return false; |
218 } |
219 } |
219 |
220 |
220 if ( this.accept.call( this.element[ 0 ], |
221 if ( this.accept.call( this.element[ 0 ], |
221 ( draggable.currentItem || draggable.element ) ) ) { |
222 ( draggable.currentItem || draggable.element ) ) ) { |
222 this._removeActiveClass(); |
223 this._removeActiveClass(); |
223 this._removeHoverClass(); |
224 this._removeHoverClass(); |
224 |
225 |
225 this._trigger( "drop", event, this.ui( draggable ) ); |
226 this._trigger( "drop", event, this.ui( draggable ) ); |
226 return this.element; |
227 return this.element; |
279 t = droppable.offset.top, |
280 t = droppable.offset.top, |
280 r = l + droppable.proportions().width, |
281 r = l + droppable.proportions().width, |
281 b = t + droppable.proportions().height; |
282 b = t + droppable.proportions().height; |
282 |
283 |
283 switch ( toleranceMode ) { |
284 switch ( toleranceMode ) { |
284 case "fit": |
285 case "fit": |
285 return ( l <= x1 && x2 <= r && t <= y1 && y2 <= b ); |
286 return ( l <= x1 && x2 <= r && t <= y1 && y2 <= b ); |
286 case "intersect": |
287 case "intersect": |
287 return ( l < x1 + ( draggable.helperProportions.width / 2 ) && // Right Half |
288 return ( l < x1 + ( draggable.helperProportions.width / 2 ) && // Right Half |
288 x2 - ( draggable.helperProportions.width / 2 ) < r && // Left Half |
289 x2 - ( draggable.helperProportions.width / 2 ) < r && // Left Half |
289 t < y1 + ( draggable.helperProportions.height / 2 ) && // Bottom Half |
290 t < y1 + ( draggable.helperProportions.height / 2 ) && // Bottom Half |
290 y2 - ( draggable.helperProportions.height / 2 ) < b ); // Top Half |
291 y2 - ( draggable.helperProportions.height / 2 ) < b ); // Top Half |
291 case "pointer": |
292 case "pointer": |
292 return isOverAxis( event.pageY, t, droppable.proportions().height ) && |
293 return isOverAxis( event.pageY, t, droppable.proportions().height ) && |
293 isOverAxis( event.pageX, l, droppable.proportions().width ); |
294 isOverAxis( event.pageX, l, droppable.proportions().width ); |
294 case "touch": |
295 case "touch": |
295 return ( |
296 return ( |
296 ( y1 >= t && y1 <= b ) || // Top edge touching |
297 ( y1 >= t && y1 <= b ) || // Top edge touching |
297 ( y2 >= t && y2 <= b ) || // Bottom edge touching |
298 ( y2 >= t && y2 <= b ) || // Bottom edge touching |
298 ( y1 < t && y2 > b ) // Surrounded vertically |
299 ( y1 < t && y2 > b ) // Surrounded vertically |
299 ) && ( |
300 ) && ( |
300 ( x1 >= l && x1 <= r ) || // Left edge touching |
301 ( x1 >= l && x1 <= r ) || // Left edge touching |
301 ( x2 >= l && x2 <= r ) || // Right edge touching |
302 ( x2 >= l && x2 <= r ) || // Right edge touching |
302 ( x1 < l && x2 > r ) // Surrounded horizontally |
303 ( x1 < l && x2 > r ) // Surrounded horizontally |
303 ); |
304 ); |
304 default: |
305 default: |
305 return false; |
306 return false; |
306 } |
307 } |
307 }; |
308 }; |
308 } )(); |
309 } )(); |
309 |
310 |
310 /* |
311 /* |
322 |
323 |
323 droppablesLoop: for ( i = 0; i < m.length; i++ ) { |
324 droppablesLoop: for ( i = 0; i < m.length; i++ ) { |
324 |
325 |
325 // No disabled and non-accepted |
326 // No disabled and non-accepted |
326 if ( m[ i ].options.disabled || ( t && !m[ i ].accept.call( m[ i ].element[ 0 ], |
327 if ( m[ i ].options.disabled || ( t && !m[ i ].accept.call( m[ i ].element[ 0 ], |
327 ( t.currentItem || t.element ) ) ) ) { |
328 ( t.currentItem || t.element ) ) ) ) { |
328 continue; |
329 continue; |
329 } |
330 } |
330 |
331 |
331 // Filter out elements in the current dragged item |
332 // Filter out elements in the current dragged item |
332 for ( j = 0; j < list.length; j++ ) { |
333 for ( j = 0; j < list.length; j++ ) { |
364 |
365 |
365 if ( !this.options ) { |
366 if ( !this.options ) { |
366 return; |
367 return; |
367 } |
368 } |
368 if ( !this.options.disabled && this.visible && |
369 if ( !this.options.disabled && this.visible && |
369 $.ui.intersect( draggable, this, this.options.tolerance, event ) ) { |
370 $.ui.intersect( draggable, this, this.options.tolerance, event ) ) { |
370 dropped = this._drop.call( this, event ) || dropped; |
371 dropped = this._drop.call( this, event ) || dropped; |
371 } |
372 } |
372 |
373 |
373 if ( !this.options.disabled && this.visible && this.accept.call( this.element[ 0 ], |
374 if ( !this.options.disabled && this.visible && this.accept.call( this.element[ 0 ], |
374 ( draggable.currentItem || draggable.element ) ) ) { |
375 ( draggable.currentItem || draggable.element ) ) ) { |
375 this.isout = true; |
376 this.isout = true; |
376 this.isover = false; |
377 this.isover = false; |
377 this._deactivate.call( this, event ); |
378 this._deactivate.call( this, event ); |
378 } |
379 } |
379 |
380 |