Skip to content

Untainted tap events #805

madrobby opened this Issue Sep 4, 2013 · 1 comment

2 participants

madrobby commented Sep 4, 2013

Right now the tap event in the touch module is tainted as "not being from direct user input" and according you can't do certain things in the event handler, such as focusing text fields or start playing audio or video.

The workaround is to use click or touchend, but it would be great to be able to directly use tap.

See also #479.

@madrobby madrobby was assigned Sep 4, 2013

This is a very complex issue. Through all the testing and research I have found only one way to get around this:
Don't implement the tap event.

What I mean is, don't allow tap subscription using $("something").on("tap", func(){});
Instead limit it to only allow subscription by using $("something").tap(func(){});

This way we can get it to work using passthrough methods in which we create an eventhandler for the touchend event on the element we want to listen for tap, and inside that eventhandler we fire the function with a custom event object that ties back into the original touchend event object.

So it would be something like this:

$.fn.tap = function(func){
    this.on('touchend.tap', function(e){
        // Generate custom event object using e
        var customEventObject = {};
        func.apply(this, customEventObject);

PS. as a side note, we might want to start looking at deprecating Touch Events in the coming months as browsers move to support Pointer Events, the cleaner way of handling input events.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.