-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.specialevent.hammer.js
39 lines (31 loc) · 1.1 KB
/
jquery.specialevent.hammer.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
/*
* special event API with Hammer.JS
* version 0.9
* author: Damien Antipa
* https://github.com/dantipa/hammer.js
*/
(function ($) {
var hammerEvents = ['hold','tap','doubletap','transformstart','transform','transformend','dragstart','drag','dragend','swipe','release'];
$.each(hammerEvents, function(i, event) {
$.event.special[event] = {
setup: function(data, namespaces, eventHandle) {
var $target = $(this),
hammer;
if (!$target.hammer) {
$target.data('hammerjs', new Hammer(this, data));
}
hammer = $target.data('hammerjs');
hammer['on'+ event] = function (ev) {
$target.trigger($.Event(event, ev));
};
},
teardown: function(namespaces) {
var $target = $(this),
hammer = $target.data('hammerjs');
if(hammer && hammer['on'+ event]) {
delete hammer['on'+ event];
}
}
};
});
}(jQuery));