Sortable icon indicating copy to clipboard operation
Sortable copied to clipboard

delay option doesn't work

Open bhecht2 opened this issue 11 years ago • 26 comments

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

bhecht2 avatar Nov 18 '15 11:11 bhecht2

Try master branch please

owen-m1 avatar Jan 07 '19 12:01 owen-m1

@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-chosen class is set
  • onStart is not called
  • the dragging class is not set

Debugging my particular case further, going up the call stack:

  • _dragStarted is not called
  • _onDragStart is not called
  • _triggerDragStart is called with: nativeDraggable=true and touch=null, resulting in event handler dragstart being set. Somehow the problem lies here, that event does not fire.
  • _onTouchMove is 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 avatar Feb 22 '19 21:02 geonanorch

@geonanorch I used your fix in the above commit. Please try master branch.

owen-m1 avatar Mar 02 '19 20:03 owen-m1

@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 avatar Mar 03 '19 10:03 geonanorch

@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.

owen-m1 avatar Mar 03 '19 11:03 owen-m1

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 🎉

emileber avatar Mar 04 '19 17:03 emileber