-
Notifications
You must be signed in to change notification settings - Fork 105
Expand file tree
/
Copy pathangular-hammer.js
More file actions
76 lines (74 loc) · 2.41 KB
/
angular-hammer.js
File metadata and controls
76 lines (74 loc) · 2.41 KB
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
/*
* Angular Hammer v2
*
* Forked from https://github.com/randallb/angular-hammer
* Updated to support https://github.com/EightMedia/hammer.js
*
* Within an Angular.js application, allows you to specify custom behaviour on Hammer.js touch events.
*
* Usage, currently as attribute only:
*
* hm-tap="{expression}"
*
* You can change the default settings for the instance by adding a second attribute with options:
*
* hm-options="{drag: false, transform: false}"
*
* Include this file, and add `hmTouchevents` to your app's dependencies.
*
* Requires Hammer.js, tested with `v1.0.1 - 2013-02-26`.
*
*/
var hmTouchevents = angular.module('hmTouchevents', []),
hmGestures = ['hmHold:hold',
'hmTap:tap',
'hmDoubletap:doubletap',
'hmDrag:drag',
'hmDragstart:dragstart',
'hmDragend:dragend',
'hmDragup:dragup',
'hmDragdown:dragdown',
'hmDragleft:dragleft',
'hmDragright:dragright',
'hmSwipe:swipe',
'hmSwipeup:swipeup',
'hmSwipedown:swipedown',
'hmSwipeleft:swipeleft',
'hmSwiperight:swiperight',
'hmTransformstart:transformstart',
'hmTransform:transform',
'hmTransformend:transformend',
'hmRotate:rotate',
'hmPinch:pinch',
'hmPinchin:pinchin',
'hmPinchout:pinchout',
'hmTouch:touch',
'hmRelease:release'];
angular.forEach(hmGestures, function(name){
var directive = name.split(':'),
directiveName = directive[0],
eventName = directive[1];
hmTouchevents.directive(directiveName, ["$parse", function($parse) {
return {
scope: true,
link: function(scope, element, attr) {
var fn, opts;
fn = $parse(attr[directiveName]);
opts = $parse(attr["hmOptions"])(scope, {});
if(opts && opts.group) {
scope.hammer = scope.hammer || Hammer(element[0], opts);
} else {
scope.hammer = Hammer(element[0], opts);
}
return scope.hammer.on(eventName, function(event) {
return scope.$apply(function() {
return fn(scope, {
$event: event
});
});
});
}
};
}
]);
});