]> source.dussan.org Git - jquery-ui.git/commitdiff
Draggable: modified snapping algorithm to use edges and corners. Fixed #8165 - Dragga...
authorZbigniew Motyka <zbigniew.motyka@gmail.com>
Mon, 29 Oct 2012 08:55:54 +0000 (09:55 +0100)
committerScott González <scott.gonzalez@gmail.com>
Wed, 17 Apr 2013 15:46:10 +0000 (11:46 -0400)
tests/unit/draggable/draggable_options.js
ui/jquery.ui.draggable.js

index 83fbc171230ae5bb1a02362c30eb9d1abc42dc6b..2cb7ec22bc0d4e69b11500417e24823717ed69e8 100644 (file)
@@ -1257,6 +1257,43 @@ test( "snap, snapMode, and snapTolerance", function() {
        deepEqual( element.offset(), { top: newY, left: newX }, "doesn't snap on the inner snapTolerance area when snapMode is outer" );
 });
 
+test( "#8165: Snapping large rectangles to small rectangles doesn't snap properly", function() {
+       expect( 1 );
+
+       var snapTolerance = 20,
+               y = 1,
+               element = $( "#draggable1" )
+                       .css({
+                               width: "50px",
+                               height: "200px"
+                       }).offset({
+                               top: y,
+                               left: 1
+                       }),
+               element2 = $( "#draggable2" )
+                       .css({
+                               width: "50px",
+                               height: "50px"
+                       }).offset({
+                               top: y + snapTolerance + 1,
+                               left: 200
+                       }),
+               newX = element2.offset().left - element.outerWidth() - snapTolerance + 1;
+
+       $( "#draggable1, #draggable2" ).draggable({
+               snap: true,
+               snapTolerance: snapTolerance
+       });
+
+       element.simulate( "drag", {
+               handle: "corner",
+               x: newX,
+               moves: 1
+       });
+
+       notDeepEqual( element.offset(), { top: y, left: newX }, "snaps even if only a side (not a corner) is inside the snapTolerance" );
+});
+
 test( "stack", function() {
        expect( 2 );
 
index a75f9e9f31362566548e66204dbbe8deedf9da9c..4c8a9d5d5f086adbbbe4712757fd1a2851f57f43 100644 (file)
@@ -850,8 +850,7 @@ $.ui.plugin.add("draggable", "snap", {
                        t = inst.snapElements[i].top;
                        b = t + inst.snapElements[i].height;
 
-                       //Yes, I know, this is insane ;)
-                       if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
+                       if(x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d) {
                                if(inst.snapElements[i].snapping) {
                                        (inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
                                }