|
1 | 1 | /** |
2 | | - * jquery.detectSwipe v2.1 |
| 2 | + * jquery.detectSwipe v2.1.1 |
3 | 3 | * jQuery Plugin to obtain touch gestures from iPhone, iPod Touch, iPad and Android |
4 | 4 | * http://github.com/marcandre/detect_swipe |
5 | 5 | * Based on touchwipe by Andreas Waltl, netCU Internetagentur (http://www.netcu.de) |
6 | 6 | */ |
7 | 7 | (function($) { |
8 | 8 |
|
9 | 9 | $.detectSwipe = { |
10 | | - version: '2.1.0', |
| 10 | + version: '2.1.1', |
11 | 11 | enabled: 'ontouchstart' in document.documentElement, |
12 | 12 | preventDefault: true, |
13 | 13 | threshold: 20 |
|
17 | 17 | startY, |
18 | 18 | isMoving = false; |
19 | 19 |
|
| 20 | + function onTouchEnd() { |
| 21 | + this.removeEventListener('touchmove', onTouchMove); |
| 22 | + this.removeEventListener('touchend', onTouchEnd); |
| 23 | + isMoving = false; |
| 24 | + } |
| 25 | + |
20 | 26 | function onTouchMove(e) { |
21 | 27 | if ($.detectSwipe.preventDefault) { e.preventDefault(); } |
22 | 28 | if(isMoving) { |
|
32 | 38 | dir = dy > 0 ? 'down' : 'up' |
33 | 39 | } |
34 | 40 | if(dir) { |
35 | | - this.removeEventListener('touchmove', onTouchMove); |
36 | | - isMoving = false; |
| 41 | + onTouchEnd.call(this); |
37 | 42 | $(this).trigger('swipe', dir).trigger('swipe' + dir); |
38 | 43 | } |
39 | 44 | } |
|
45 | 50 | startY = e.touches[0].pageY; |
46 | 51 | isMoving = true; |
47 | 52 | this.addEventListener('touchmove', onTouchMove, false); |
| 53 | + this.addEventListener('touchend', onTouchEnd, false); |
48 | 54 | } |
49 | 55 | } |
50 | 56 |
|
51 | 57 | function setup() { |
52 | 58 | this.addEventListener('touchstart', onTouchStart, false); |
53 | 59 | } |
54 | 60 |
|
| 61 | + function teardown() { |
| 62 | + this.removeEventListener('touchstart', onTouchStart); |
| 63 | + } |
| 64 | + |
55 | 65 | $.event.special.swipe = { setup: setup }; |
56 | 66 |
|
57 | 67 | $.each(['left', 'up', 'down', 'right'], function () { |
|
0 commit comments