On touch devices, the click event can be somewhat slow (there is a noticeable delay between the end of touch and the triggering of click). One common solution is to replace the click event by a touchend event, but this will break compatibility on devices which use both touch and mouse events (for instance, laptops with touch screens). Another common solution is to use a small JS lib, but this works only for links and performs badly for delegated events.
To enhance the user experience and provide a better responding feeling, the template provides a touch-click technique: a callback is bound to both events touchend and click, and a special function is used to determine which event to handle.
First, start by listening both to click and touchend events:
$(selector).on('touchend click', function(event) {
...
});
Then use the template method to determine if the event should be processed:
$(selector).on('touchend click', function(event)
{
// Check if valid touch-click event
if (!$.template.processTouchClick(this, event))
{
return;
}
// Process event here
});
This features works as follow: