]> source.dussan.org Git - jquery-ui.git/commitdiff
Draggable: Account for margins when snapping
authorMike Sherov <mike.sherov@gmail.com>
Thu, 14 Aug 2014 13:50:02 +0000 (09:50 -0400)
committerMike Sherov <mike.sherov@gmail.com>
Thu, 14 Aug 2014 13:50:02 +0000 (09:50 -0400)
Fixes #9724

tests/unit/draggable/draggable_options.js
ui/draggable.js

index f59a33693d2b2f556754f4562f2d274667cf14c1..4f319e404e9b4ba2cbee14ecdee9f73ea365a3bd 100644 (file)
@@ -961,6 +961,10 @@ test( "snap, snapMode, and snapTolerance", function() {
                }),
                element2 = $( "#draggable2" ).draggable();
 
+       // http://bugs.jqueryui.com/ticket/9724
+       // Draggable: Snapping coordinates thrown off by margin on draggable
+       element.css( "margin", "3px" );
+
        element.offset({
                top: 1,
                left: 1
index a6de2889cc37069ec5048457f3e353c03f16baaf..b96fca0d208c449cbc5dabac26ab718e7c8bea33 100644 (file)
@@ -916,9 +916,9 @@ $.ui.plugin.add("draggable", "snap", {
 
                for (i = inst.snapElements.length - 1; i >= 0; i--){
 
-                       l = inst.snapElements[i].left;
+                       l = inst.snapElements[i].left - inst.margins.left;
                        r = l + inst.snapElements[i].width;
-                       t = inst.snapElements[i].top;
+                       t = inst.snapElements[i].top - inst.margins.top;
                        b = t + inst.snapElements[i].height;
 
                        if ( x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d || !$.contains( inst.snapElements[ i ].item.ownerDocument, inst.snapElements[ i ].item ) ) {
@@ -935,16 +935,16 @@ $.ui.plugin.add("draggable", "snap", {
                                ls = Math.abs(l - x2) <= d;
                                rs = Math.abs(r - x1) <= d;
                                if (ts) {
-                                       ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
+                                       ui.position.top = inst._convertPositionTo("relative", { top: t - inst.helperProportions.height, left: 0 }).top;
                                }
                                if (bs) {
-                                       ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top - inst.margins.top;
+                                       ui.position.top = inst._convertPositionTo("relative", { top: b, left: 0 }).top;
                                }
                                if (ls) {
-                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left - inst.margins.left;
+                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l - inst.helperProportions.width }).left;
                                }
                                if (rs) {
-                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left - inst.margins.left;
+                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r }).left;
                                }
                        }
 
@@ -956,16 +956,16 @@ $.ui.plugin.add("draggable", "snap", {
                                ls = Math.abs(l - x1) <= d;
                                rs = Math.abs(r - x2) <= d;
                                if (ts) {
-                                       ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top - inst.margins.top;
+                                       ui.position.top = inst._convertPositionTo("relative", { top: t, left: 0 }).top;
                                }
                                if (bs) {
-                                       ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top - inst.margins.top;
+                                       ui.position.top = inst._convertPositionTo("relative", { top: b - inst.helperProportions.height, left: 0 }).top;
                                }
                                if (ls) {
-                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left - inst.margins.left;
+                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: l }).left;
                                }
                                if (rs) {
-                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left - inst.margins.left;
+                                       ui.position.left = inst._convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left;
                                }
                        }