]>
git.proxmox.com Git - sencha-touch.git/blob - src/src/event/recognizer/Swipe.js
2 * A base class used for both {@link Ext.event.recognizer.VerticalSwipe} and {@link Ext.event.recognizer.HorizontalSwipe}
7 Ext
.define('Ext.event.recognizer.Swipe', {
8 extend
: 'Ext.event.recognizer.SingleTouch',
10 handledEvents
: ['swipestart', 'swipe'],
13 * @member Ext.dom.Element
15 * Fires when there is a swipe
16 * When listening to this, ensure you know about the {@link Ext.event.Event#direction} property in the `event` object.
17 * @param {Ext.event.Event} event The {@link Ext.event.Event} event encapsulating the DOM event.
18 * @param {HTMLElement} node The target of the event.
19 * @param {Object} options The options object passed to Ext.mixin.Observable.addListener.
23 * @property {Number} direction
24 * The direction of the swipe. Available options are:
31 * __Note:__ In order to recognize swiping up and down, you must enable the vertical swipe recognizer.
33 * **This is only available when the event type is `swipe`**
34 * @member Ext.event.Event
38 * @property {Number} duration
39 * The duration of the swipe.
41 * **This is only available when the event type is `swipe`**
42 * @member Ext.event.Event
46 MAX_OFFSET_EXCEEDED
: 0x10,
47 MAX_DURATION_EXCEEDED
: 0x11,
48 DISTANCE_NOT_ENOUGH
: 0x12
57 onTouchStart: function(e
) {
58 if (this.callParent(arguments
) === false) {
62 var touch
= e
.changedTouches
[0];
64 this.startTime
= e
.time
;
66 this.isHorizontal
= true;
67 this.isVertical
= true;
69 this.startX
= touch
.pageX
;
70 this.startY
= touch
.pageY
;
73 onTouchMove: function(e
) {
74 var touch
= e
.changedTouches
[0],
77 deltaX
= x
- this.startX
,
78 deltaY
= y
- this.startY
,
79 absDeltaX
= Math
.abs(x
- this.startX
),
80 absDeltaY
= Math
.abs(y
- this.startY
),
81 duration
= e
.time
- this.startTime
,
82 minDistance
= this.getMinDistance(),
86 if (time
- this.startTime
> this.getMaxDuration()) {
87 return this.fail(this.self
.MAX_DURATION_EXCEEDED
);
90 if (this.isHorizontal
&& absDeltaY
> this.getMaxOffset()) {
91 this.isHorizontal
= false;
94 if (this.isVertical
&& absDeltaX
> this.getMaxOffset()) {
95 this.isVertical
= false;
98 if (!this.isVertical
|| !this.isHorizontal
) {
99 if (this.isHorizontal
&& absDeltaX
< minDistance
) {
100 direction
= (deltaX
< 0) ? 'left' : 'right';
101 distance
= absDeltaX
;
103 else if (this.isVertical
&& absDeltaY
< minDistance
) {
104 direction
= (deltaY
< 0) ? 'up' : 'down';
105 distance
= absDeltaY
;
109 if (direction
&& !this.started
) {
112 this.fire('swipestart', e
, [touch
], {
114 direction
: direction
,
120 if (!this.isHorizontal
&& !this.isVertical
) {
121 return this.fail(this.self
.MAX_OFFSET_EXCEEDED
);
125 onTouchEnd: function(e
) {
126 if (this.onTouchMove(e
) === false) {
130 var touch
= e
.changedTouches
[0],
133 deltaX
= x
- this.startX
,
134 deltaY
= y
- this.startY
,
135 absDeltaX
= Math
.abs(deltaX
),
136 absDeltaY
= Math
.abs(deltaY
),
137 minDistance
= this.getMinDistance(),
138 duration
= e
.time
- this.startTime
,
141 if (this.isVertical
&& absDeltaY
< minDistance
) {
142 this.isVertical
= false;
145 if (this.isHorizontal
&& absDeltaX
< minDistance
) {
146 this.isHorizontal
= false;
149 if (this.isHorizontal
) {
150 direction
= (deltaX
< 0) ? 'left' : 'right';
151 distance
= absDeltaX
;
153 else if (this.isVertical
) {
154 direction
= (deltaY
< 0) ? 'up' : 'down';
155 distance
= absDeltaY
;
158 return this.fail(this.self
.DISTANCE_NOT_ENOUGH
);
161 this.started
= false;
163 this.fire('swipe', e
, [touch
], {
165 direction
: direction
,