jquery-ui-touch-punch icon indicating copy to clipboard operation
jquery-ui-touch-punch copied to clipboard

Click Event Fires Twice Android

Open tmiller71 opened this issue 11 years ago • 4 comments

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,");
    });
});

tmiller71 avatar Apr 19 '13 16:04 tmiller71

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
});

tmiller71 avatar Apr 19 '13 21:04 tmiller71

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

krzbor avatar May 27 '13 17:05 krzbor

The krzbor solution work for me. I test on iPad Chrome.

marcelo2605 avatar Aug 07 '13 20:08 marcelo2605

Thanks krzbor it works (oneplus 5t)

thomasFoglia avatar Feb 03 '19 14:02 thomasFoglia