mirror of
https://github.com/jquery/jquery-ui.git
synced 2024-11-21 11:04:24 +00:00
Draggable: modified snapping algorithm to use edges and corners. Fixed #8165 - Draggable: Snapping doesn't take top/left into account properly(cherry picked from commit bd126a9c1c
)
This commit is contained in:
parent
149e6eb0bc
commit
f74a908056
@ -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" );
|
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() {
|
test( "stack", function() {
|
||||||
expect( 2 );
|
expect( 2 );
|
||||||
|
|
||||||
|
3
ui/jquery.ui.draggable.js
vendored
3
ui/jquery.ui.draggable.js
vendored
@ -850,8 +850,7 @@ $.ui.plugin.add("draggable", "snap", {
|
|||||||
t = inst.snapElements[i].top;
|
t = inst.snapElements[i].top;
|
||||||
b = t + inst.snapElements[i].height;
|
b = t + inst.snapElements[i].height;
|
||||||
|
|
||||||
//Yes, I know, this is insane ;)
|
if(x2 < l - d || x1 > r + d || y2 < t - d || y1 > b + d) {
|
||||||
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(inst.snapElements[i].snapping) {
|
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 })));
|
(inst.options.snap.release && inst.options.snap.release.call(inst.element, event, $.extend(inst._uiHash(), { snapItem: inst.snapElements[i].item })));
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user