Skip to content
This repository has been archived by the owner on Oct 8, 2021. It is now read-only.

Commit

Permalink
Taphold: add option to prevent tap from being fired on taphold Fixes #…
Browse files Browse the repository at this point in the history
…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 71e6dfc
Showing 1 changed file with 6 additions and 4 deletions.
10 changes: 6 additions & 4 deletions js/events/touch.js
Expand Up @@ -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;
}
Expand All @@ -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 );
}
}
Expand All @@ -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 );
});
Expand Down

0 comments on commit 71e6dfc

Please sign in to comment.