This is code always scary to ... touch, but here we go ...
start() is registered for both touchstart and mousedown. On touch devices, an unhandled (as in !e.defaultPrevented) touch event will generate a corresponding mousedown. So a lot of the start() handler runs twice on touch devices. It only works because:
When the main branch if (piece && element && stillSelected && board.isDraggable(s, orig)) { is reached, e.preventDefault() will have been called.
Everything else is idempotent (clearing drawings, unsetting premoves, redraw)
But as reported in #257, the user event handler select may be fired twice.
With this patch:
A direct mouse event is handled as before (the e.preventDefault() branch)
A touch event that takes the e.preventDefault() branch is handled as before, and will not generate a corresponding mouse event in any case
A touch event that does not take the e.preventDefault() branch is no longer handled at all. It will generate a corresponding mouse event, which is then handled as before.
This is code always scary to ... touch, but here we go ...
start()
is registered for bothtouchstart
andmousedown
. On touch devices, an unhandled (as in!e.defaultPrevented
) touch event will generate a correspondingmousedown
. So a lot of thestart()
handler runs twice on touch devices. It only works because:if (piece && element && stillSelected && board.isDraggable(s, orig)) {
is reached,e.preventDefault()
will have been called.Everything else is idempotent (clearing drawings, unsetting premoves, redraw)
But as reported in #257, the user event handler
select
may be fired twice.With this patch:
e.preventDefault()
branch)e.preventDefault()
branch is handled as before, and will not generate a corresponding mouse event in any casee.preventDefault()
branch is no longer handled at all. It will generate a corresponding mouse event, which is then handled as before.