forked from mud/JSGestureRecognizer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
long-press.js
60 lines (44 loc) · 1.47 KB
/
long-press.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
module.exports = LongPressGestureRecognizer;
var GestureRecognizer = require("./gesture-recognizer");
function LongPressGestureRecognizer()
{
// FIXME: implement .numberOfTapsRequired
this.allowableMovement = 10;
this.minimumPressDuration = 500;
this.numberOfTouchesRequired = 1;
GestureRecognizer.call(this);
}
LongPressGestureRecognizer.prototype = {
constructor: LongPressGestureRecognizer,
__proto__: GestureRecognizer.prototype,
touchesBegan: function(event)
{
if (event.currentTarget !== this.target)
return;
event.preventDefault();
GestureRecognizer.prototype.touchesBegan.call(this, event);
if (this.numberOfTouches !== this.numberOfTouchesRequired) {
this.enterFailedState();
return;
}
this._startPoint = this.locationInElement();
this._timerId = window.setTimeout(this.enterRecognizedState.bind(this), this.minimumPressDuration);
},
touchesMoved: function(event)
{
event.preventDefault();
if (this._startPoint.distanceToPoint(this.locationInElement()) > this.allowableMovement)
this.enterFailedState();
},
touchesEnded: function(event)
{
event.preventDefault();
if (this.numberOfTouches !== this.numberOfTouchesRequired)
this.enterFailedState();
},
reset: function()
{
window.clearTimeout(this._timerId);
delete this._timerId;
}
};