Skip to content

Commit 87081b8

Browse files
willholleymikesherov
authored andcommitted
Droppable: only consider pointer location with tolerance "pointer"
Fixes #4977 Closes gh-991
1 parent d434fdb commit 87081b8

File tree

2 files changed

+20
-10
lines changed

2 files changed

+20
-10
lines changed

tests/unit/droppable/droppable_options.js

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ test( "tolerance, intersect", function() {
9696
*/
9797

9898
test( "tolerance, pointer", function() {
99-
expect( 2 );
99+
expect( 3 );
100100

101101
var draggable, droppable,
102102
dataset = [
@@ -132,6 +132,19 @@ test( "tolerance, pointer", function() {
132132
dy: ( data[ 1 ] - $( draggable ).position().top )
133133
});
134134
});
135+
136+
// http://bugs.jqueryui.com/ticket/4977 - tolerance, pointer - bug when pointer outside draggable
137+
draggable.css({ top: 0, left: 0 }).draggable( "option", "axis", "x" );
138+
droppable.css({ top: 15, left: 15 });
139+
140+
droppable.unbind( "drop" ).bind( "drop", function() {
141+
ok( true, "drop fires as long as pointer is within droppable" );
142+
});
143+
144+
$( draggable ).simulate( "drag", {
145+
dx: 10,
146+
dy: 10
147+
});
135148
});
136149

137150
/*

ui/droppable.js

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -191,7 +191,7 @@ $.widget( "ui.droppable", {
191191
!inst.options.disabled &&
192192
inst.options.scope === draggable.options.scope &&
193193
inst.accept.call( inst.element[ 0 ], ( draggable.currentItem || draggable.element ) ) &&
194-
$.ui.intersect( draggable, $.extend( inst, { offset: inst.element.offset() } ), inst.options.tolerance )
194+
$.ui.intersect( draggable, $.extend( inst, { offset: inst.element.offset() } ), inst.options.tolerance, event )
195195
) { childrenIntersection = true; return false; }
196196
});
197197
if ( childrenIntersection ) {
@@ -229,14 +229,13 @@ $.ui.intersect = (function() {
229229
return ( x >= reference ) && ( x < ( reference + size ) );
230230
}
231231

232-
return function( draggable, droppable, toleranceMode ) {
232+
return function( draggable, droppable, toleranceMode, event ) {
233233

234234
if ( !droppable.offset ) {
235235
return false;
236236
}
237237

238-
var draggableLeft, draggableTop,
239-
x1 = ( draggable.positionAbs || draggable.position.absolute ).left,
238+
var x1 = ( draggable.positionAbs || draggable.position.absolute ).left,
240239
y1 = ( draggable.positionAbs || draggable.position.absolute ).top,
241240
x2 = x1 + draggable.helperProportions.width,
242241
y2 = y1 + draggable.helperProportions.height,
@@ -254,9 +253,7 @@ $.ui.intersect = (function() {
254253
t < y1 + ( draggable.helperProportions.height / 2 ) && // Bottom Half
255254
y2 - ( draggable.helperProportions.height / 2 ) < b ); // Top Half
256255
case "pointer":
257-
draggableLeft = ( ( draggable.positionAbs || draggable.position.absolute ).left + ( draggable.clickOffset || draggable.offset.click ).left );
258-
draggableTop = ( ( draggable.positionAbs || draggable.position.absolute ).top + ( draggable.clickOffset || draggable.offset.click ).top );
259-
return isOverAxis( draggableTop, t, droppable.proportions().height ) && isOverAxis( draggableLeft, l, droppable.proportions().width );
256+
return isOverAxis( event.pageY, t, droppable.proportions().height ) && isOverAxis( event.pageX, l, droppable.proportions().width );
260257
case "touch":
261258
return (
262259
( y1 >= t && y1 <= b ) || // Top edge touching
@@ -326,7 +323,7 @@ $.ui.ddmanager = {
326323
if ( !this.options ) {
327324
return;
328325
}
329-
if ( !this.options.disabled && this.visible && $.ui.intersect( draggable, this, this.options.tolerance ) ) {
326+
if ( !this.options.disabled && this.visible && $.ui.intersect( draggable, this, this.options.tolerance, event ) ) {
330327
dropped = this._drop.call( this, event ) || dropped;
331328
}
332329

@@ -363,7 +360,7 @@ $.ui.ddmanager = {
363360
}
364361

365362
var parentInstance, scope, parent,
366-
intersects = $.ui.intersect( draggable, this, this.options.tolerance ),
363+
intersects = $.ui.intersect( draggable, this, this.options.tolerance, event ),
367364
c = !intersects && this.isover ? "isout" : ( intersects && !this.isover ? "isover" : null );
368365
if ( !c ) {
369366
return;

0 commit comments

Comments
 (0)