delay option doesn't work
Hi,
I am checking the demo: http://jsbin.com/videlojafi/edit?html,js,output
It doesn't work for me on either firefox, or IE (10). Once removing the delay line, or changing it to 0, everything starts to work
Try master branch please
@owen-m1 I just did (using Firefox 61.0.2), no luck but I think that I have a lead.
Imho the delay parameter is very useful to:
- handle contenteditables (e.g. to allow selecting within a draggable contenteditable)-
- or even plain clicks (e.g. short touch to activate, long touch to initiate drag).
Something like:
Sortable.create(el, {
draggable: '.zone_out',
delay: 200,
touchStartThreshold: 5,
onChoose: () => console.log('sortable onChoose'),
onUnchoose: () => console.log('sortable onUnchoose'),
onStart: () => console.log('sortable onStart'),
onEnd: () => console.log('sortable onEnd'),
});
will not work, but commenting out delay will make it work, More observations when delay is set:
- the
sortable-chosenclass is set onStartis not called- the
draggingclass is not set
Debugging my particular case further, going up the call stack:
_dragStartedis not called_onDragStartis not called_triggerDragStartis called with:nativeDraggable=trueandtouch=null, resulting in event handlerdragstartbeing set. Somehow the problem lies here, that event does not fire._onTouchMoveis not called (as expected based on the previous point)
I then looked at _prepareDragStart to try and pinpoint the issue. Somehow it makes a difference whether dragStartFn is called synchronously or delayed. Don't ask me why, but the lines:
// Make the element draggable
dragEl.draggable = _this.nativeDraggable;
should be moved outside of dragStartFn (so executed whether delayed or not) for the dragstart event to be fired in delayed mode. I am not claiming that it is the fix because I do not fully understand why it works, but here is a patch that works for me (based on the current master commit):
$ diff -e Sortable.js Sortable.js.org
819,820d
808a
// Make the element draggable
dragEl.draggable = _this.nativeDraggable;
.
@geonanorch I used your fix in the above commit. Please try master branch.
@owen-m1 just gave it a go, works for me, thanks. Would be nice to have confirmation from other folks who contributed to the thread though, just to be sure...
I guess that some browsers initiate dragging on the mousedown/touchstart event (seems natural) and that draggable must be set by then at the latest. Not sure what the spec really says.
@geonanorch IE and Edge seemed to have that paticular restraint as well. However, IE and Edge will also not cancel a dragstart if the draggable property is removed after the mousedown, making a delay feature impossible on these browsers.
While I was still receiving notifications for this issue, it's been more than 2 years since I haven't touched this lib, which was in a Backbone project 2 job hops ago.
Though I'm glad that the development of Sortable was taken over by someone! Good job 🎉