3434 * also pass an optional object as the second constructor argument. If you're
3535 * interested in holdstart/holdmove/holdend events, pass {holdEvents:true} as
3636 * this second argument. Otherwise they will not be generated.
37+ * If you want to customize the pan threshold, pass
38+ * {panThreshold:X, mousePanThreshold:Y} (X and Y in pixels) in the options
39+ * argument.
3740 *
3841 * Implementation note: event processing is done with a simple finite-state
3942 * machine. This means that in general, the various kinds of gestures are
@@ -58,6 +61,9 @@ var GestureDetector = (function() {
5861 function GD (e , options ) {
5962 this .element = e ;
6063 this .options = options || {};
64+ this .options .panThreshold = this .options .panThreshold || GD .PAN_THRESHOLD ;
65+ this .options .mousePanThreshold =
66+ this .options .mousePanThreshold || GD .MOUSE_PAN_THRESHOLD ;
6167 this .state = initialState ;
6268 this .timers = {};
6369 this .listeningForMouseEvents = true ;
@@ -159,7 +165,7 @@ var GestureDetector = (function() {
159165 var event = this .element .ownerDocument .createEvent ('CustomEvent' );
160166 event .initCustomEvent (type , true , true , detail );
161167 this .target .dispatchEvent (event );
162- }
168+ };
163169
164170 //
165171 // Tuneable parameters
@@ -363,8 +369,8 @@ var GestureDetector = (function() {
363369 if (t .identifier !== d .touch1 )
364370 return ;
365371
366- if (abs (t .screenX - d .start .screenX ) > GD . PAN_THRESHOLD ||
367- abs (t .screenY - d .start .screenY ) > GD . PAN_THRESHOLD ) {
372+ if (abs (t .screenX - d .start .screenX ) > d . options . panThreshold ||
373+ abs (t .screenY - d .start .screenY ) > d . options . panThreshold ) {
368374 d .clearTimer ('holdtimeout' );
369375 d .switchTo (panStartedState , e , t );
370376 }
@@ -711,8 +717,8 @@ var GestureDetector = (function() {
711717 // then switch to the mouse panning state. Otherwise remain
712718 // in this state
713719
714- if (abs (e .screenX - d .start .screenX ) > GD . MOUSE_PAN_THRESHOLD ||
715- abs (e .screenY - d .start .screenY ) > GD . MOUSE_PAN_THRESHOLD ) {
720+ if (abs (e .screenX - d .start .screenX ) > d . options . mousePanThreshold ||
721+ abs (e .screenY - d .start .screenY ) > d . options . mousePanThreshold ) {
716722 d .clearTimer ('holdtimeout' );
717723 d .switchTo (mousePannedState , e );
718724 }
0 commit comments