Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
No way to stop a link from being followed with some custom event (tap, taphold) #1464
When a normal click event is bound to a link, returning false will stop the link from being followed. But this doesn't appear to work with the some of the custom link types.
I've tried vclick, tap, and taphold in Chrome and can't find any way to cancel the default behaviour of the link without also using a click event. I'm using version 1.0a4.1.
See http://jsfiddle.net/YL8hj/ for an example.
I'm not sure the "tap" event was intended to be an alias for the "click" event. I think the intent was to give the developer some way to trigger an action on touchend (for touch devices) instead of waiting the 300ms or so before the browser got around to synthesizing the related mouseup/click. With that intent in mind, I'm not sure calling preventDefault() on a "tap" event should prevent the default action of a link.
Now "vclick" is a different story. Calling preventDefault() on a "vclick" event should prevent a link for executing its default action. It actually does do what you expect on a touch device, but there is currently a bug in the mouse event handling code for jquery.mobile.vmouse.js where the isDefaultPrevented(), isPropagationStopped(), and isImmediatePropagationStopped() settings are not being propagated from the virtual event to the original mouse event. I have a fix for this.
In all 3 cases ("vclick", "tap", and "taphold") the stopPropagation() and stopImmediatePropagation() should NOT execute any handlers that follow the one doing the stop, and the events should cease to bubble up the DOM tree.
There seems to be a bug in the implementation of "taphold" where 2 elements in the same parent/child hierarchy that are bound to "taphold" each fire-off their own "taphold" timer. This means that if the child element is the thing being tapped, 2 timers will be fired off, one for the child and one for the parent/ancestor, resulting in 2 different events bubbling up the tree.