From 433ef9d433e9baa464cd0b313b82efa6f1d65556 Mon Sep 17 00:00:00 2001 From: David Hansen Date: Wed, 23 Jan 2013 11:46:10 -0700 Subject: [PATCH] Interactions: Fixed an off-by-one error in isOverAxis. --- tests/unit/droppable/droppable_methods.js | 31 ++++++++++++++++++++++- ui/jquery.ui.droppable.js | 2 +- ui/jquery.ui.sortable.js | 2 +- 3 files changed, 32 insertions(+), 3 deletions(-) diff --git a/tests/unit/droppable/droppable_methods.js b/tests/unit/droppable/droppable_methods.js index f7682d262..ce3d8f72f 100644 --- a/tests/unit/droppable/droppable_methods.js +++ b/tests/unit/droppable/droppable_methods.js @@ -88,4 +88,33 @@ test( "disable", function() { equal( actual, expected, "disable is chainable" ); }); -})(jQuery); +test( "intersect", function() { + expect( 8 ); + + var actual, data, + draggable = $( "
" ).appendTo( "#qunit-fixture" ).css({ width: 10, height: 10, position: "absolute" }).draggable(), + droppable = $( "
" ).appendTo( "#qunit-fixture" ).css({ width: 10, height: 10, position: "absolute", top: 5, left: 5 }).droppable(), + dataset = [ + [ -1, -1, false, "too far up and left" ], + [ -1, 0, false, "too far left" ], + [ 0, -1, false, "too far up" ], + [ 0, 0, true, "top left corner" ], + [ 9, 9, true, "bottom right corner" ], + [ 10, 9, false, "too far right" ], + [ 9, 10, false, "too far down" ], + [ 10, 10, false, "too far down and right" ] + ], + x = 0; + + for ( ; x < dataset.length; x++ ) { + data = dataset[ x ]; + $( draggable ).simulate( "drag", { + dx: ( data[ 0 ] - $( draggable ).position().left ), + dy: ( data[ 1 ] - $( draggable ).position().top ) + }); + actual = $.ui.intersect( $( draggable ).draggable( "instance" ), $( droppable ).droppable( "instance" ), "pointer" ); + equal( actual, data[ 2 ], data[ 3 ] ); + } +}); + +})( jQuery ); diff --git a/ui/jquery.ui.droppable.js b/ui/jquery.ui.droppable.js index 6bc4b594d..808009dc1 100644 --- a/ui/jquery.ui.droppable.js +++ b/ui/jquery.ui.droppable.js @@ -17,7 +17,7 @@ (function( $, undefined ) { function isOverAxis( x, reference, size ) { - return ( x > reference ) && ( x < ( reference + size ) ); + return ( x >= reference ) && ( x < ( reference + size ) ); } $.widget("ui.droppable", { diff --git a/ui/jquery.ui.sortable.js b/ui/jquery.ui.sortable.js index c7794f06a..9c7bf446c 100644 --- a/ui/jquery.ui.sortable.js +++ b/ui/jquery.ui.sortable.js @@ -16,7 +16,7 @@ (function( $, undefined ) { function isOverAxis( x, reference, size ) { - return ( x > reference ) && ( x < ( reference + size ) ); + return ( x >= reference ) && ( x < ( reference + size ) ); } function isFloating(item) { -- 2.39.5