Diffstat (limited to 'frontend/gamma/js/Zepto/touch.js') (more/less context) (ignore whitespace changes)
-rw-r--r-- | frontend/gamma/js/Zepto/touch.js | 113 |
1 files changed, 0 insertions, 113 deletions
diff --git a/frontend/gamma/js/Zepto/touch.js b/frontend/gamma/js/Zepto/touch.js deleted file mode 100644 index af109b9..0000000 --- a/frontend/gamma/js/Zepto/touch.js +++ b/dev/null | |||
@@ -1,113 +0,0 @@ | |||
1 | // Zepto.js | ||
2 | // (c) 2010-2012 Thomas Fuchs | ||
3 | // Zepto.js may be freely distributed under the MIT license. | ||
4 | |||
5 | ;(function($){ | ||
6 | var touch = {}, | ||
7 | touchTimeout, tapTimeout, swipeTimeout, | ||
8 | longTapDelay = 750, longTapTimeout | ||
9 | |||
10 | function parentIfText(node) { | ||
11 | return 'tagName' in node ? node : node.parentNode | ||
12 | } | ||
13 | |||
14 | function swipeDirection(x1, x2, y1, y2) { | ||
15 | var xDelta = Math.abs(x1 - x2), yDelta = Math.abs(y1 - y2) | ||
16 | return xDelta >= yDelta ? (x1 - x2 > 0 ? 'Left' : 'Right') : (y1 - y2 > 0 ? 'Up' : 'Down') | ||
17 | } | ||
18 | |||
19 | function longTap() { | ||
20 | longTapTimeout = null | ||
21 | if (touch.last) { | ||
22 | touch.el.trigger('longTap') | ||
23 | touch = {} | ||
24 | } | ||
25 | } | ||
26 | |||
27 | function cancelLongTap() { | ||
28 | if (longTapTimeout) clearTimeout(longTapTimeout) | ||
29 | longTapTimeout = null | ||
30 | } | ||
31 | |||
32 | function cancelAll() { | ||
33 | if (touchTimeout) clearTimeout(touchTimeout) | ||
34 | if (tapTimeout) clearTimeout(tapTimeout) | ||
35 | if (swipeTimeout) clearTimeout(swipeTimeout) | ||
36 | if (longTapTimeout) clearTimeout(longTapTimeout) | ||
37 | touchTimeout = tapTimeout = swipeTimeout = longTapTimeout = null | ||
38 | touch = {} | ||
39 | } | ||
40 | |||
41 | $(document).ready(function(){ | ||
42 | var now, delta | ||
43 | |||
44 | $(document.body) | ||
45 | .bind('touchstart', function(e){ | ||
46 | now = Date.now() | ||
47 | delta = now - (touch.last || now) | ||
48 | touch.el = $(parentIfText(e.touches[0].target)) | ||
49 | touchTimeout && clearTimeout(touchTimeout) | ||
50 | touch.x1 = e.touches[0].pageX | ||
51 | touch.y1 = e.touches[0].pageY | ||
52 | if (delta > 0 && delta <= 250) touch.isDoubleTap = true | ||
53 | touch.last = now | ||
54 | longTapTimeout = setTimeout(longTap, longTapDelay) | ||
55 | }) | ||
56 | .bind('touchmove', function(e){ | ||
57 | cancelLongTap() | ||
58 | touch.x2 = e.touches[0].pageX | ||
59 | touch.y2 = e.touches[0].pageY | ||
60 | }) | ||
61 | .bind('touchend', function(e){ | ||
62 | cancelLongTap() | ||
63 | |||
64 | // swipe | ||
65 | if ((touch.x2 && Math.abs(touch.x1 - touch.x2) > 30) || | ||
66 | (touch.y2 && Math.abs(touch.y1 - touch.y2) > 30)) | ||
67 | |||
68 | swipeTimeout = setTimeout(function() { | ||
69 | touch.el.trigger('swipe') | ||
70 | touch.el.trigger('swipe' + (swipeDirection(touch.x1, touch.x2, touch.y1, touch.y2))) | ||
71 | touch = {} | ||
72 | }, 0) | ||
73 | |||
74 | // normal tap | ||
75 | else if ('last' in touch) | ||
76 | |||
77 | // delay by one tick so we can cancel the 'tap' event if 'scroll' fires | ||
78 | // ('tap' fires before 'scroll') | ||
79 | tapTimeout = setTimeout(function() { | ||
80 | |||
81 | // trigger universal 'tap' with the option to cancelTouch() | ||
82 | // (cancelTouch cancels processing of single vs double taps for faster 'tap' response) | ||
83 | var event = $.Event('tap') | ||
84 | event.cancelTouch = cancelAll | ||
85 | touch.el.trigger(event) | ||
86 | |||
87 | // trigger double tap immediately | ||
88 | if (touch.isDoubleTap) { | ||
89 | touch.el.trigger('doubleTap') | ||
90 | touch = {} | ||
91 | } | ||
92 | |||
93 | // trigger single tap after 250ms of inactivity | ||
94 | else { | ||
95 | touchTimeout = setTimeout(function(){ | ||
96 | touchTimeout = null | ||
97 | touch.el.trigger('singleTap') | ||
98 | touch = {} | ||
99 | }, 250) | ||
100 | } | ||
101 | |||
102 | }, 0) | ||
103 | |||
104 | }) | ||
105 | .bind('touchcancel', cancelAll) | ||
106 | |||
107 | $(window).bind('scroll', cancelAll) | ||
108 | }) | ||
109 | |||
110 | ;['swipe', 'swipeLeft', 'swipeRight', 'swipeUp', 'swipeDown', 'doubleTap', 'tap', 'singleTap', 'longTap'].forEach(function(m){ | ||
111 | $.fn[m] = function(callback){ return this.bind(m, callback) } | ||
112 | }) | ||
113 | })(Zepto) | ||