1 | import { defaults } from '../util/util';
|
2 | import { DIRECTION_HORIZONTAL, DIRECTION_VERTICAL, Hammer } from './hammer';
|
3 |
|
4 |
|
5 |
|
6 |
|
7 |
|
8 |
|
9 | var Gesture = (function () {
|
10 | |
11 |
|
12 |
|
13 |
|
14 | function Gesture(element, opts) {
|
15 | if (opts === void 0) { opts = {}; }
|
16 | this._callbacks = {};
|
17 | this.isListening = false;
|
18 | defaults(opts, {
|
19 | domEvents: true
|
20 | });
|
21 | this.element = element;
|
22 |
|
23 | this.direction = opts.direction || 'x';
|
24 | opts.direction = this.direction === 'x' ?
|
25 | DIRECTION_HORIZONTAL :
|
26 | DIRECTION_VERTICAL;
|
27 | this._options = opts;
|
28 | }
|
29 | |
30 |
|
31 |
|
32 |
|
33 | Gesture.prototype.options = function (opts) {
|
34 | Object.assign(this._options, opts);
|
35 | };
|
36 | |
37 |
|
38 |
|
39 |
|
40 |
|
41 | Gesture.prototype.on = function (type, cb) {
|
42 | if (type === 'pinch' || type === 'rotate') {
|
43 | this._hammer.get(type).set({ enable: true });
|
44 | }
|
45 | this._hammer.on(type, cb);
|
46 | (this._callbacks[type] || (this._callbacks[type] = [])).push(cb);
|
47 | };
|
48 | |
49 |
|
50 |
|
51 |
|
52 |
|
53 | Gesture.prototype.off = function (type, cb) {
|
54 | this._hammer.off(type, this._callbacks[type] ? cb : null);
|
55 | };
|
56 | |
57 |
|
58 |
|
59 | Gesture.prototype.listen = function () {
|
60 | if (!this.isListening) {
|
61 | this._hammer = Hammer(this.element, this._options);
|
62 | }
|
63 | this.isListening = true;
|
64 | };
|
65 | |
66 |
|
67 |
|
68 | Gesture.prototype.unlisten = function () {
|
69 | var eventType;
|
70 | var i;
|
71 | if (this._hammer && this.isListening) {
|
72 | for (eventType in this._callbacks) {
|
73 | for (i = 0; i < this._callbacks[eventType].length; i++) {
|
74 | this._hammer.off(eventType, this._callbacks[eventType]);
|
75 | }
|
76 | }
|
77 | this._hammer.destroy();
|
78 | }
|
79 | this._callbacks = {};
|
80 | this._hammer = null;
|
81 | this.isListening = false;
|
82 | };
|
83 | |
84 |
|
85 |
|
86 | Gesture.prototype.destroy = function () {
|
87 | this.unlisten();
|
88 | this.element = this._options = null;
|
89 | };
|
90 | return Gesture;
|
91 | }());
|
92 | export { Gesture };
|
93 | function Gesture_tsickle_Closure_declarations() {
|
94 |
|
95 | Gesture.prototype._hammer;
|
96 |
|
97 | Gesture.prototype._options;
|
98 |
|
99 | Gesture.prototype._callbacks;
|
100 |
|
101 | Gesture.prototype.element;
|
102 |
|
103 | Gesture.prototype.direction;
|
104 |
|
105 | Gesture.prototype.isListening;
|
106 | }
|
107 |
|
\ | No newline at end of file |