Skip to content

Commit b662fee

Browse files
committed
Draggable: Fixed snapping of bigger objects to smaller objects. Fixed #8165 - Problem with snap option when dragging big rect.
1 parent a63c091 commit b662fee

File tree

1 file changed

+11
-2
lines changed

1 file changed

+11
-2
lines changed

ui/jquery.ui.draggable.js

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -847,8 +847,17 @@ $.ui.plugin.add("draggable", "snap", {
847847
t = inst.snapElements[i].top;
848848
b = t + inst.snapElements[i].height;
849849

850-
//Yes, I know, this is insane ;)
851-
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))) {
850+
//This checks if any of the corners or sides are within snap distance.
851+
if(!(
852+
(l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || // Check the left top corner
853+
(l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || // Check the left bottom corner
854+
(l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || // Check the right top corner
855+
(l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d) || // Check the right bottom corner
856+
(l > x1 && x2 > r && t-d < y1 && y1 < b+d) || // Check the top side
857+
(l > x1 && x2 > r && t-d < y2 && y2 < b+d) || // Check the bottom side
858+
(l-d < x1 && x1 < r+d && t > y1 && y2 > b) || // Check the right side
859+
(l-d < x2 && x2 < r+d && t > y1 && y2 > b) // Check the left side
860+
)) {
852861
if(inst.snapElements[i].snapping) {
853862
(inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
854863
}

0 commit comments

Comments
 (0)