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

Commit 71e6dfc

Browse files
committed
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
1 parent 70877cf commit 71e6dfc

File tree

1 file changed

+6
-4
lines changed

1 file changed

+6
-4
lines changed

js/events/touch.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -78,13 +78,14 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
7878
// also handles taphold
7979
$.event.special.tap = {
8080
tapholdThreshold: 750,
81-
81+
emitTapOnTaphold: true,
8282
setup: function() {
8383
var thisObject = this,
84-
$this = $( thisObject );
84+
$this = $( thisObject ),
85+
isTaphold = false;
8586

8687
$this.bind( "vmousedown", function( event ) {
87-
88+
isTaphold = false;
8889
if ( event.which && event.which !== 1 ) {
8990
return false;
9091
}
@@ -109,7 +110,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
109110

110111
// ONLY trigger a 'tap' event if the start target is
111112
// the same as the stop target.
112-
if ( origTarget === event.target ) {
113+
if ( $.event.special.tap.emitTapOnTaphold && !isTaphold && origTarget === event.target ) {
113114
triggerCustomEvent( thisObject, "tap", event );
114115
}
115116
}
@@ -119,6 +120,7 @@ define( [ "jquery", "../jquery.mobile.vmouse", "../jquery.mobile.support.touch"
119120
$document.bind( "vmousecancel", clearTapHandlers );
120121

121122
timer = setTimeout( function() {
123+
isTaphold = true;
122124
triggerCustomEvent( thisObject, "taphold", $.Event( "taphold", { target: origTarget } ) );
123125
}, $.event.special.tap.tapholdThreshold );
124126
});

0 commit comments

Comments
 (0)