Skip to content

Commit 7b1966c

Browse files
author
Scott Jehl
committed
Merge pull request jquery-archive#2015 from mlitwin/bug_1992
Fixes jquery-archive#1992; Swipe threshold constants are configurable
2 parents e567742 + 1ef7313 commit 7b1966c

File tree

1 file changed

+12
-4
lines changed

1 file changed

+12
-4
lines changed

js/jquery.mobile.event.js

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,14 @@ $.event.special.tap = {
115115

116116
// also handles swipeleft, swiperight
117117
$.event.special.swipe = {
118+
scrollSupressionThreshold: 10, // More than this horizontal displacement, and we will suppress scrolling.
119+
120+
durationThreshold: 1000, // More time than this, and it isn't a swipe.
121+
122+
horizontalDistanceThreshold: 30, // Swipe horizontal displacement must be more than this.
123+
124+
verticalDistanceThreshold: 75, // Swipe vertical displacement must be less than this.
125+
118126
setup: function() {
119127
var thisObject = this,
120128
$this = $( thisObject );
@@ -144,7 +152,7 @@ $.event.special.swipe = {
144152
};
145153

146154
// prevent scrolling
147-
if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > 10 ) {
155+
if ( Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.scrollSupressionThreshold ) {
148156
event.preventDefault();
149157
}
150158
}
@@ -154,9 +162,9 @@ $.event.special.swipe = {
154162
$this.unbind( touchMoveEvent, moveHandler );
155163

156164
if ( start && stop ) {
157-
if ( stop.time - start.time < 1000 &&
158-
Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > 30 &&
159-
Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < 75 ) {
165+
if ( stop.time - start.time < $.event.special.swipe.durationThreshold &&
166+
Math.abs( start.coords[ 0 ] - stop.coords[ 0 ] ) > $.event.special.swipe.horizontalDistanceThreshold &&
167+
Math.abs( start.coords[ 1 ] - stop.coords[ 1 ] ) < $.event.special.swipe.verticalDistanceThreshold ) {
160168

161169
start.origin.trigger( "swipe" )
162170
.trigger( start.coords[0] > stop.coords[ 0 ] ? "swipeleft" : "swiperight" );

0 commit comments

Comments
 (0)