]> git.proxmox.com Git - sencha-touch.git/blob - src/src/event/recognizer/HorizontalSwipe.js
import Sencha Touch 2.4.2 source
[sencha-touch.git] / src / src / event / recognizer / HorizontalSwipe.js
1 /**
2 * A event recognizer created to recognize horizontal swipe movements.
3 *
4 * @private
5 */
6 Ext.define('Ext.event.recognizer.HorizontalSwipe', {
7 extend: 'Ext.event.recognizer.Swipe',
8
9 handledEvents: ['swipe'],
10
11 onTouchStart: function(e) {
12 if (this.callParent(arguments) === false) {
13 return false;
14 }
15
16 var touch = e.changedTouches[0];
17
18 this.startTime = e.time;
19
20 this.startX = touch.pageX;
21 this.startY = touch.pageY;
22 },
23
24 onTouchMove: function(e) {
25 var touch = e.changedTouches[0],
26 y = touch.pageY,
27 absDeltaY = Math.abs(y - this.startY),
28 time = e.time,
29 maxDuration = this.getMaxDuration(),
30 maxOffset = this.getMaxOffset();
31
32 if (time - this.startTime > maxDuration) {
33 return this.fail(this.self.MAX_DURATION_EXCEEDED);
34 }
35
36 if (absDeltaY > maxOffset) {
37 return this.fail(this.self.MAX_OFFSET_EXCEEDED);
38 }
39 },
40
41 onTouchEnd: function(e) {
42 if (this.onTouchMove(e) !== false) {
43 var touch = e.changedTouches[0],
44 x = touch.pageX,
45 deltaX = x - this.startX,
46 distance = Math.abs(deltaX),
47 duration = e.time - this.startTime,
48 minDistance = this.getMinDistance(),
49 direction;
50
51 if (distance < minDistance) {
52 return this.fail(this.self.DISTANCE_NOT_ENOUGH);
53 }
54
55 direction = (deltaX < 0) ? 'left' : 'right';
56
57 this.fire('swipe', e, [touch], {
58 touch: touch,
59 direction: direction,
60 distance: distance,
61 duration: duration
62 });
63 }
64 }
65 });