Skip to content

Commit

Permalink
Add option to only apply delay on touch events (#1482)
Browse files Browse the repository at this point in the history
  • Loading branch information
seanogdev authored and owen-m1 committed Apr 20, 2019
1 parent 9fae052 commit 640eccd
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 1 deletion.
8 changes: 8 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ var sortable = new Sortable(el, {
group: "name", // or { name: "...", pull: [true, false, 'clone', array], put: [true, false, array] }
sort: true, // sorting inside list
delay: 0, // time in milliseconds to define when the sorting should start
delayOnTouchOnly: false, // only delay if user is using touch
touchStartThreshold: 0, // px, how many pixels the point should move before cancelling a delayed drag event
disabled: false, // Disables the sortable if set to true.
store: null, // @see Store
Expand Down Expand Up @@ -247,6 +248,13 @@ Demo: https://jsbin.com/zosiwah/edit?js,output
---


#### `delayOnTouchOnly` option
Whether or not the delay should be applied only if the user is using touch (eg. on a mobile device). No delay will be applied in any other case. Defaults to `false`.


---


#### `swapThreshold` option
Percentage of the target that the swap zone will take up, as a float between `0` and `1`.

Expand Down
3 changes: 2 additions & 1 deletion Sortable.js
Original file line number Diff line number Diff line change
Expand Up @@ -529,6 +529,7 @@
dragoverBubble: false,
dataIdAttr: 'data-id',
delay: 0,
delayOnTouchOnly: false,
touchStartThreshold: parseInt(window.devicePixelRatio, 10) || 1,
forceFallback: false,
fallbackClass: 'sortable-fallback',
Expand Down Expand Up @@ -819,7 +820,7 @@
}

// Delay is impossible for native DnD in Edge or IE
if (options.delay && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
if (options.delay && (options.delayOnTouchOnly ? touch : true) && (!this.nativeDraggable || !(Edge || IE11OrLess))) {
// If the user moves the pointer or let go the click or touch
// before the delay has been reached:
// disable the delayed drag
Expand Down

0 comments on commit 640eccd

Please sign in to comment.