Skip to content

Commit 64bbc61

Browse files
committed
add distance option
1 parent d6076f5 commit 64bbc61

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

source/_limited_drop_targets.html.haml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,12 @@
1212
%strong serialization
1313
of the lists
1414
%li
15-
Decrease sort sensitivity
15+
Decrease sort
16+
%strong sensitivity
17+
%li
18+
Start dragging after a
19+
%strong distance
20+
has been met
1621
%p= show_code_button
1722
%h3 Serialize result
1823
%pre#serialize_output

source/js/examples/limited_drop_targets.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ $(function () {
1515
serialize: function (parent, children, isContainer) {
1616
return isContainer ? children.join() : parent.text()
1717
},
18-
tolerance: 6
18+
tolerance: 6,
19+
distance: 10
1920
})
2021
})

source/js/jquery-sortable.js

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@
4949
},
5050
// The css selector of the containers
5151
containerSelector: "ol, ul",
52+
distance: 0,
5253
// The css selector of the drag handle
5354
handle: "",
5455
// The css selector of the items
@@ -238,6 +239,9 @@
238239
e.preventDefault()
239240

240241
if(!this.dragging){
242+
if(!this.distanceMet(e))
243+
return
244+
241245
processChildContainers(this.item, this.options.containerSelector, "disable", true)
242246

243247
this.options.onDragStart(this.item, this.itemContainer, groupDefaults.onDragStart)
@@ -368,6 +372,12 @@
368372
this.lastPointer = this.pointer
369373
this.pointer = pointer
370374
},
375+
distanceMet: function (e) {
376+
return (Math.max(
377+
Math.abs(this.pointer.left - e.pageX),
378+
Math.abs(this.pointer.top - e.pageY)
379+
) >= this.options.distance)
380+
},
371381
addContainer: function (container) {
372382
this.containers.push(container);
373383
},

0 commit comments

Comments
 (0)