Writing a rich web application I have the need to support all types of users, some are using a mouse, some are using a touch screen (e.g. on a mobile device). So the W3C PointerEvent API is exactly what I need to handle the user interactions. This works fine, except for one important case: double clicks.
There are a few things in the way:
- There is no (high level) event like "
pointerdblclick
", only the low levelpointerdown
andpointerup
are available. - To fix that and calculate the double click myself it is often recommended to use the property
detail
of the emitted event and check whether it has the value2
. But this property is always0
in my case. - But even tracking this number myself will not work perfectly, as the OS (and possible setting by the user) is defining the maximum delay that is making two clicks to a double click.
So what can I do to react on a double click by mouse or a double tab by touch when all other user interactions are handled by listening to the PointerEvents? Can this be even made in such a way that the OS setting of the double click delay is respected?
Note 1: I still must be able to detect a normal click (by listening to pointerdown
and pointerup
) as well as a drag (by listening to pointerdown
, pointermove
and later pointerup
)
Note 2: I'm using "pure" JavaScript and modern browsers, jQuery is no option.