Skip to content

Commit 4dad6bb

Browse files
committed
Droppable: Account for draggable margins when detecting hover
Fixes #6876
1 parent 98b7a7d commit 4dad6bb

File tree

2 files changed

+53
-4
lines changed

2 files changed

+53
-4
lines changed

tests/unit/droppable/droppable_options.js

Lines changed: 51 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,11 +89,60 @@ test( "hoverClass", function() {
8989
test( "tolerance, fit", function() {
9090
ok(false, 'missing test - untested code is broken code');
9191
});
92+
*/
9293

9394
test( "tolerance, intersect", function() {
94-
ok(false, 'missing test - untested code is broken code');
95+
expect( 2 );
96+
97+
var draggable, droppable,
98+
dataset = [
99+
[ 0, 0, false, "too far up and left" ],
100+
[ 6, 0, false, "too far up" ],
101+
[ 0, 6, false, "too far left" ],
102+
[ 6, 6, true, "top left corner" ],
103+
[ 14, 14, true, "bottom right corner" ],
104+
[ 15, 6, false, "too far right" ],
105+
[ 6, 15, false, "too far down" ],
106+
[ 15, 15, false, "too far down and right" ]
107+
];
108+
109+
draggable = $( "<div />" )
110+
.appendTo( "#qunit-fixture" )
111+
.css({
112+
width: 10,
113+
height: 10,
114+
position: "absolute",
115+
116+
// http://bugs.jqueryui.com/ticket/6876
117+
// Droppable: droppable region is offset by draggables margin
118+
marginTop: 3,
119+
marginLeft: 3
120+
})
121+
.draggable();
122+
123+
droppable = $( "<div />" )
124+
.appendTo( "#qunit-fixture" )
125+
.css({ width: 10, height: 10, position: "absolute", top: 13, left: 13 })
126+
.droppable({ tolerance: "intersect" });
127+
128+
$.each( dataset, function() {
129+
var data = this;
130+
131+
draggable.css({
132+
top: 0,
133+
left: 0
134+
});
135+
136+
droppable.unbind( "drop" ).bind( "drop", function() {
137+
equal( true, data[ 2 ], data[ 3 ] );
138+
});
139+
140+
$( draggable ).simulate( "drag", {
141+
dx: data[ 0 ],
142+
dy: data[ 1 ]
143+
});
144+
});
95145
});
96-
*/
97146

98147
test( "tolerance, pointer", function() {
99148
expect( 3 );

ui/droppable.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,8 +235,8 @@ $.ui.intersect = (function() {
235235
return false;
236236
}
237237

238-
var x1 = ( draggable.positionAbs || draggable.position.absolute ).left,
239-
y1 = ( draggable.positionAbs || draggable.position.absolute ).top,
238+
var x1 = ( draggable.positionAbs || draggable.position.absolute ).left + draggable.margins.left,
239+
y1 = ( draggable.positionAbs || draggable.position.absolute ).top + draggable.margins.top,
240240
x2 = x1 + draggable.helperProportions.width,
241241
y2 = y1 + draggable.helperProportions.height,
242242
l = droppable.offset.left,

0 commit comments

Comments
 (0)