Skip to content

Commit b1e959b

Browse files
uunicornwinged unicorn
authored and
winged unicorn
committed
Draggable: Use relative coordinates for snapElements
Since scrolling position may change while dragging, so is the absolute coordinates of the snapElements. Fixes #14694
1 parent 74f8a0a commit b1e959b

File tree

1 file changed

+12
-35
lines changed

1 file changed

+12
-35
lines changed

ui/widgets/draggable.js

Lines changed: 12 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1086,7 +1086,7 @@ $.ui.plugin.add( "draggable", "snap", {
10861086
$( o.snap.constructor !== String ? ( o.snap.items || ":data(ui-draggable)" ) : o.snap )
10871087
.each( function() {
10881088
var $t = $( this ),
1089-
$o = $t.offset();
1089+
$o = i._convertPositionTo( "relative", $t.offset() );
10901090
if ( this !== i.element[ 0 ] ) {
10911091
i.snapElements.push( {
10921092
item: this,
@@ -1102,8 +1102,9 @@ $.ui.plugin.add( "draggable", "snap", {
11021102
var ts, bs, ls, rs, l, r, t, b, i, first,
11031103
o = inst.options,
11041104
d = o.snapTolerance,
1105-
x1 = ui.offset.left, x2 = x1 + inst.helperProportions.width,
1106-
y1 = ui.offset.top, y2 = y1 + inst.helperProportions.height;
1105+
p = inst._convertPositionTo( "relative", ui.offset ),
1106+
x1 = p.left, x2 = x1 + inst.helperProportions.width,
1107+
y1 = p.top, y2 = y1 + inst.helperProportions.height;
11071108

11081109
for ( i = inst.snapElements.length - 1; i >= 0; i-- ) {
11091110

@@ -1133,28 +1134,16 @@ $.ui.plugin.add( "draggable", "snap", {
11331134
ls = Math.abs( l - x2 ) <= d;
11341135
rs = Math.abs( r - x1 ) <= d;
11351136
if ( ts ) {
1136-
ui.position.top = inst._convertPositionTo( "relative", {
1137-
top: t - inst.helperProportions.height,
1138-
left: 0
1139-
} ).top;
1137+
ui.position.top = t - inst.helperProportions.height;
11401138
}
11411139
if ( bs ) {
1142-
ui.position.top = inst._convertPositionTo( "relative", {
1143-
top: b,
1144-
left: 0
1145-
} ).top;
1140+
ui.position.top = b;
11461141
}
11471142
if ( ls ) {
1148-
ui.position.left = inst._convertPositionTo( "relative", {
1149-
top: 0,
1150-
left: l - inst.helperProportions.width
1151-
} ).left;
1143+
ui.position.left = l - inst.helperProportions.width;
11521144
}
11531145
if ( rs ) {
1154-
ui.position.left = inst._convertPositionTo( "relative", {
1155-
top: 0,
1156-
left: r
1157-
} ).left;
1146+
ui.position.left = r;
11581147
}
11591148
}
11601149

@@ -1166,28 +1155,16 @@ $.ui.plugin.add( "draggable", "snap", {
11661155
ls = Math.abs( l - x1 ) <= d;
11671156
rs = Math.abs( r - x2 ) <= d;
11681157
if ( ts ) {
1169-
ui.position.top = inst._convertPositionTo( "relative", {
1170-
top: t,
1171-
left: 0
1172-
} ).top;
1158+
ui.position.top = t;
11731159
}
11741160
if ( bs ) {
1175-
ui.position.top = inst._convertPositionTo( "relative", {
1176-
top: b - inst.helperProportions.height,
1177-
left: 0
1178-
} ).top;
1161+
ui.position.top = b - inst.helperProportions.height;
11791162
}
11801163
if ( ls ) {
1181-
ui.position.left = inst._convertPositionTo( "relative", {
1182-
top: 0,
1183-
left: l
1184-
} ).left;
1164+
ui.position.left = l;
11851165
}
11861166
if ( rs ) {
1187-
ui.position.left = inst._convertPositionTo( "relative", {
1188-
top: 0,
1189-
left: r - inst.helperProportions.width
1190-
} ).left;
1167+
ui.position.left = r - inst.helperProportions.width;
11911168
}
11921169
}
11931170

0 commit comments

Comments
 (0)