-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
115 lines (92 loc) · 1.7 KB
/
index.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
110
111
112
113
114
/**
* Module dependencies.
*/
var Hammer = require('hammer')
, Emitter = require('emitter');
/**
* Bind gestures to `el`.
*
* @param {Element} el
* @return {Gesture}
* @api public
*/
module.exports = function(el){
return new Gesture(el);
};
/**
* Initalize a new `Gesture` with the given `el`.
*
* @param {Element} el
* @api public
*/
function Gesture(el) {
this.hammer = new Hammer(el);
this.el = el;
this.bind();
}
/**
* Mixin Emitter
*/
Emitter(Gesture.prototype);
/**
* Bind to hammer.js events.
*
* @api private
*/
Gesture.prototype.bind = function(){
var self = this;
var hammer = this.hammer;
// drag start
hammer.ondragstart = function(e){
self.emit('drag start', e);
};
// drag
hammer.ondrag = function(e){
self.emit('drag', e);
};
// drag end
hammer.ondragend = function(e){
self.emit('drag end', e);
};
// tag
hammer.ontap = function(e){
self.emit('tap', e);
};
// double tag
hammer.ondoubletap = function(e){
self.emit('double tap', e);
};
// hold
hammer.onhold = function(e){
self.emit('hold', e);
};
// release
hammer.onrelease = function(e){
self.emit('release', e);
};
// transform start
hammer.ontransformstart = function(e){
self.emit('transform start', e);
};
// transform
hammer.ontransform = function(e){
self.emit('transform', e);
};
// transform end
hammer.ontransformend = function(e){
self.emit('transform end', e);
};
// swipe left / right
hammer.onswipe = function(e){
self.emit('swipe', e);
self.emit('swipe ' + e.direction, e);
};
};
/**
* Unbind events.
*
* @api public
*/
Gesture.prototype.unbind = function(){
this.hammer.destroy();
};