Permalink
Browse files

Taphold: add option to prevent tap from being fired on taphold Fixes #…

…3803 - Taphold fires tap event as well. Thanks to @jtblin for the concept pr #5980
  • Loading branch information...
arschmitz committed May 8, 2013
1 parent 70877cf commit 71e6dfcbc0bbd9abe7d9657fe165c30bacac7535
Showing with 6 additions and 4 deletions.
  1. +6 −4 js/events/touch.js
View
@@ -78,13 +78,14 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
// also handles taphold
$.event.special.tap = {
tapholdThreshold: 750,
emitTapOnTaphold: true,
setup: function() {
var thisObject = this,
$this = $( thisObject );
$this = $( thisObject ),
isTaphold = false;
$this.bind( "vmousedown", function( event ) {
isTaphold = false;
if ( event.which && event.which !== 1 ) {
return false;
}
@@ -109,7 +110,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
// ONLY trigger a 'tap' event if the start target is
// the same as the stop target.
if ( origTarget === event.target ) {
if ( $.event.special.tap.emitTapOnTaphold && !isTaphold && origTarget === event.target ) {
triggerCustomEvent( thisObject, "tap", event );
}
}
@@ -119,6 +120,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
$document.bind( "vmousecancel", clearTapHandlers );
timer = setTimeout( function() {
isTaphold = true;
triggerCustomEvent( thisObject, "taphold", $.Event( "taphold", { target: origTarget } ) );
}, $.event.special.tap.tapholdThreshold );
});

0 comments on commit 71e6dfc

Please sign in to comment.