Skip to content

Commit 433ef9d

Browse files
hansedemikesherov
authored andcommitted
Interactions: Fixed an off-by-one error in isOverAxis.
1 parent 2eb89f0 commit 433ef9d

File tree

3 files changed

+32
-3
lines changed

3 files changed

+32
-3
lines changed

tests/unit/droppable/droppable_methods.js

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,4 +88,33 @@ test( "disable", function() {
8888
equal( actual, expected, "disable is chainable" );
8989
});
9090

91-
})(jQuery);
91+
test( "intersect", function() {
92+
expect( 8 );
93+
94+
var actual, data,
95+
draggable = $( "<div />" ).appendTo( "#qunit-fixture" ).css({ width: 10, height: 10, position: "absolute" }).draggable(),
96+
droppable = $( "<div />" ).appendTo( "#qunit-fixture" ).css({ width: 10, height: 10, position: "absolute", top: 5, left: 5 }).droppable(),
97+
dataset = [
98+
[ -1, -1, false, "too far up and left" ],
99+
[ -1, 0, false, "too far left" ],
100+
[ 0, -1, false, "too far up" ],
101+
[ 0, 0, true, "top left corner" ],
102+
[ 9, 9, true, "bottom right corner" ],
103+
[ 10, 9, false, "too far right" ],
104+
[ 9, 10, false, "too far down" ],
105+
[ 10, 10, false, "too far down and right" ]
106+
],
107+
x = 0;
108+
109+
for ( ; x < dataset.length; x++ ) {
110+
data = dataset[ x ];
111+
$( draggable ).simulate( "drag", {
112+
dx: ( data[ 0 ] - $( draggable ).position().left ),
113+
dy: ( data[ 1 ] - $( draggable ).position().top )
114+
});
115+
actual = $.ui.intersect( $( draggable ).draggable( "instance" ), $( droppable ).droppable( "instance" ), "pointer" );
116+
equal( actual, data[ 2 ], data[ 3 ] );
117+
}
118+
});
119+
120+
})( jQuery );

ui/jquery.ui.droppable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
(function( $, undefined ) {
1818

1919
function isOverAxis( x, reference, size ) {
20-
return ( x > reference ) && ( x < ( reference + size ) );
20+
return ( x >= reference ) && ( x < ( reference + size ) );
2121
}
2222

2323
$.widget("ui.droppable", {

ui/jquery.ui.sortable.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
(function( $, undefined ) {
1717

1818
function isOverAxis( x, reference, size ) {
19-
return ( x > reference ) && ( x < ( reference + size ) );
19+
return ( x >= reference ) && ( x < ( reference + size ) );
2020
}
2121

2222
function isFloating(item) {

0 commit comments

Comments
 (0)