-
Notifications
You must be signed in to change notification settings - Fork 60
/
BaseTap.js
109 lines (103 loc) · 3.71 KB
/
BaseTap.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
/*
* Copyright 2012 Amadeus s.a.s.
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
var Aria = require("../Aria");
var ariaTouchGesture = require("./Gesture");
/**
* Contains delegated handler for a tap event
*/
module.exports = Aria.classDefinition({
$classpath : "aria.touch.BaseTap",
$extends : ariaTouchGesture,
$statics : {
/**
* The move tolerance to validate the gesture.
* @type Integer
*/
MARGIN : 10
},
$prototype : {
/**
* Initial listeners for the Tap gesture.
* @protected
*/
_getInitialListenersList : function () {
return [{
evt : this.touchEventMap.touchstart,
cb : {
fn : this._tapStart,
scope : this
}
}];
},
/**
* Additional listeners for the Tap gesture.
* @protected
*/
_getAdditionalListenersList : function () {
return [{
evt : this.touchEventMap.touchmove,
cb : {
fn : this._tapMove,
scope : this
}
}, {
evt : this.touchEventMap.touchend,
cb : {
fn : this._tapEnd,
scope : this
}
}];
},
/**
* Tap start mgmt: gesture is started if only one touch.
* @param {Object} event the original event
* @protected
* @return {Boolean} false if preventDefault is true
*/
_tapStart : function (event) {
var status = this._gestureStart(event);
return (status == null)
? ((event.returnValue != null) ? event.returnValue : !event.defaultPrevented)
: status;
},
/**
* Tap move mgmt: gesture continues if only one touch and if the move is within margins.
* @param {Object} event the original event
* @protected
* @return {Boolean} false if preventDefault is true
*/
_tapMove : function (event) {
var position = aria.touch.Event.getPositions(event);
if (this.MARGIN >= this._calculateDistance(this.startData.positions[0].x, this.startData.positions[0].y, position[0].x, position[0].y)) {
var status = this._gestureMove(event);
return (status == null) ? this._gestureCancel(event) : status;
} else {
return this._gestureCancel(event);
}
},
/**
* Tap end mgmt: gesture ends if only one touch.
* @param {Object} event the original event
* @protected
* @return {Boolean} false if preventDefault is true
*/
_tapEnd : function (event) {
var status = this._gestureEnd(event);
return (status == null) ? this._gestureCancel(event) : (event.returnValue != null)
? event.returnValue
: !event.defaultPrevented;
}
}
});