jquery-ui-touch-punch
jquery-ui-touch-punch copied to clipboard
Click Event Fires Twice Android
If I bind a click event to a draggable element the click event is fired twice on the stock Android browser and Dolphin browser in version 4.1.1. Based on the samples and adding the code below will reproduce the behavior.
$(document).ready(function () { $("#draggable").click(function (event) { if ($(this).is('.ui-draggable-dragging')) { return; } // Just log the event for testing purposes, real code would be here $("#divConsole").append("click,"); }); });
I came up with a workaround that seems to be working. I added a global variable:
var touchEnabled = "ontouchend" in document;
I replaced:
d(f,"click");
with
jQuery(f.originalEvent.changedTouches[0].target).trigger("click", ['touchpunch']);
then in the click handler for the given control:
$("myselector).click(function (event, src) { if (touchEnabled && src != "touchpunch") { return; } // do some stuff });
I found a solution (do not know if the best). I removed event.preventDefault (); from simulateMouseEvent, added event.preventDefault () in mouseProto._touchMove. In addition, I removed simulateMouseEvent (event, 'click') from mouseProto._touchEnd. In the present solution the events are not locked touch and release, which brings up the standard action (click).
The krzbor solution work for me. I test on iPad Chrome.
Thanks krzbor it works (oneplus 5t)