1
1
/*
2
2
* Hammer.JS
3
- * version 0.5.1
3
+ * version 0.6
4
4
* author: Eight Media
5
5
* https://github.com/EightMedia/hammer.js
6
6
*/
@@ -13,6 +13,10 @@ function Hammer(element, options, undefined)
13
13
prevent_default : false ,
14
14
css_hacks : true ,
15
15
16
+ swipe : true ,
17
+ swipe_time : 200 , // ms
18
+ swipe_min_distance : 20 , // pixels
19
+
16
20
drag : true ,
17
21
drag_vertical : true ,
18
22
drag_horizontal : true ,
@@ -319,6 +323,48 @@ function Hammer(element, options, undefined)
319
323
}
320
324
} ,
321
325
326
+ // swipe gesture
327
+ // fired on touchend
328
+ swipe : function ( event )
329
+ {
330
+ if ( ! _pos . move ) {
331
+ return ;
332
+ }
333
+
334
+ // get the distance we moved
335
+ var _distance_x = _pos . move [ 0 ] . x - _pos . start [ 0 ] . x ;
336
+ var _distance_y = _pos . move [ 0 ] . y - _pos . start [ 0 ] . y ;
337
+ _distance = Math . sqrt ( _distance_x * _distance_x + _distance_y * _distance_y ) ;
338
+
339
+ // compare the kind of gesture by time
340
+ var now = new Date ( ) . getTime ( ) ;
341
+ var touch_time = now - _touch_start_time ;
342
+
343
+ if ( options . swipe && ( options . swipe_time > touch_time ) && ( _distance > options . swipe_min_distance ) ) {
344
+ // calculate the angle
345
+ _angle = getAngle ( _pos . start [ 0 ] , _pos . move [ 0 ] ) ;
346
+ _direction = self . getDirectionFromAngle ( _angle ) ;
347
+
348
+ _gesture = 'swipe' ;
349
+
350
+ var position = { x : _pos . move [ 0 ] . x - _offset . left ,
351
+ y : _pos . move [ 0 ] . y - _offset . top } ;
352
+
353
+ var event_obj = {
354
+ originalEvent : event ,
355
+ position : position ,
356
+ direction : _direction ,
357
+ distance : _distance ,
358
+ distanceX : _distance_x ,
359
+ distanceY : _distance_y ,
360
+ angle : _angle
361
+ } ;
362
+
363
+ // normal slide event
364
+ triggerEvent ( "swipe" , event_obj ) ;
365
+ }
366
+ } ,
367
+
322
368
323
369
// drag gesture
324
370
// fired on mousemove
@@ -539,6 +585,11 @@ function Hammer(element, options, undefined)
539
585
_mousedown = false ;
540
586
_event_end = event ;
541
587
588
+
589
+ // swipe gesture
590
+ gestures . swipe ( event ) ;
591
+
592
+
542
593
// drag gesture
543
594
// dragstart is triggered, so dragend is possible
544
595
if ( _gesture == 'drag' ) {
0 commit comments