]> source.dussan.org Git - jquery-ui.git/commitdiff
Droppable: Account for draggable margins when detecting hover
authorMike Sherov <mike.sherov@gmail.com>
Wed, 13 Aug 2014 23:36:07 +0000 (19:36 -0400)
committerMike Sherov <mike.sherov@gmail.com>
Wed, 13 Aug 2014 23:36:07 +0000 (19:36 -0400)
Fixes #6876

tests/unit/droppable/droppable_options.js
ui/droppable.js

index 9bfa258814f0ccbd238b22a9a52c8cc03e4d29d8..047858abf11ee965da96c33af800a1b76f2d23e0 100644 (file)
@@ -89,11 +89,60 @@ test( "hoverClass", function() {
 test( "tolerance, fit", function() {
        ok(false, 'missing test - untested code is broken code');
 });
+*/
 
 test( "tolerance, intersect", function() {
-       ok(false, 'missing test - untested code is broken code');
+       expect( 2 );
+
+       var draggable, droppable,
+               dataset = [
+                       [ 0, 0, false, "too far up and left" ],
+                       [ 6, 0, false, "too far up" ],
+                       [ 0, 6, false, "too far left" ],
+                       [ 6, 6, true, "top left corner" ],
+                       [ 14, 14, true, "bottom right corner" ],
+                       [ 15, 6, false, "too far right" ],
+                       [ 6, 15, false, "too far down" ],
+                       [ 15, 15, false, "too far down and right" ]
+               ];
+
+       draggable = $( "<div />" )
+               .appendTo( "#qunit-fixture" )
+               .css({
+                       width: 10,
+                       height: 10,
+                       position: "absolute",
+
+                       // http://bugs.jqueryui.com/ticket/6876
+                       // Droppable: droppable region is offset by draggables margin
+                       marginTop: 3,
+                       marginLeft: 3
+               })
+               .draggable();
+
+       droppable = $( "<div />" )
+               .appendTo( "#qunit-fixture" )
+               .css({ width: 10, height: 10, position: "absolute", top: 13, left: 13 })
+               .droppable({ tolerance: "intersect" });
+
+       $.each( dataset, function() {
+               var data = this;
+
+               draggable.css({
+                       top: 0,
+                       left: 0
+               });
+
+               droppable.unbind( "drop" ).bind( "drop", function() {
+                       equal( true, data[ 2 ], data[ 3 ] );
+               });
+
+               $( draggable ).simulate( "drag", {
+                       dx: data[ 0 ],
+                       dy: data[ 1 ]
+               });
+       });
 });
-*/
 
 test( "tolerance, pointer", function() {
        expect( 3 );
index fce8d9bd9b27f5570d984cf2f9110f0cad31f5fe..e889d89cda36a76fe0be1212c6ffbc298267cb99 100644 (file)
@@ -235,8 +235,8 @@ $.ui.intersect = (function() {
                        return false;
                }
 
-               var x1 = ( draggable.positionAbs || draggable.position.absolute ).left,
-                       y1 = ( draggable.positionAbs || draggable.position.absolute ).top,
+               var x1 = ( draggable.positionAbs || draggable.position.absolute ).left + draggable.margins.left,
+                       y1 = ( draggable.positionAbs || draggable.position.absolute ).top + draggable.margins.top,
                        x2 = x1 + draggable.helperProportions.width,
                        y2 = y1 + draggable.helperProportions.height,
                        l = droppable.offset.left,