1 | import { defaults } from '../util/util';
|
2 | import { PanRecognizer } from './recognizers';
|
3 | import { pointerCoord } from '../util/dom';
|
4 | import { UIEventManager } from './ui-event-manager';
|
5 |
|
6 |
|
7 |
|
8 | var PanGesture = (function () {
|
9 | |
10 |
|
11 |
|
12 |
|
13 |
|
14 | function PanGesture(plt, element, opts) {
|
15 | if (opts === void 0) { opts = {}; }
|
16 | this.plt = plt;
|
17 | this.element = element;
|
18 | defaults(opts, {
|
19 | threshold: 20,
|
20 | maxAngle: 40,
|
21 | direction: 'x',
|
22 | zone: true,
|
23 | capture: false,
|
24 | passive: false,
|
25 | });
|
26 | this.events = new UIEventManager(plt);
|
27 | if (opts.domController) {
|
28 | this.debouncer = opts.domController.debouncer();
|
29 | }
|
30 | this.gestute = opts.gesture;
|
31 | this.direction = opts.direction;
|
32 | this.eventsConfig = {
|
33 | element: this.element,
|
34 | pointerDown: this.pointerDown.bind(this),
|
35 | pointerMove: this.pointerMove.bind(this),
|
36 | pointerUp: this.pointerUp.bind(this),
|
37 | zone: opts.zone,
|
38 | capture: opts.capture,
|
39 | passive: opts.passive
|
40 | };
|
41 | if (opts.threshold > 0) {
|
42 | this.detector = new PanRecognizer(opts.direction, opts.threshold, opts.maxAngle);
|
43 | }
|
44 | }
|
45 | |
46 |
|
47 |
|
48 | PanGesture.prototype.listen = function () {
|
49 | if (!this.isListening) {
|
50 | this.pointerEvents = this.events.pointerEvents(this.eventsConfig);
|
51 | this.isListening = true;
|
52 | }
|
53 | };
|
54 | |
55 |
|
56 |
|
57 | PanGesture.prototype.unlisten = function () {
|
58 | if (this.isListening) {
|
59 | this.gestute && this.gestute.release();
|
60 | this.events.unlistenAll();
|
61 | this.isListening = false;
|
62 | }
|
63 | };
|
64 | |
65 |
|
66 |
|
67 | PanGesture.prototype.destroy = function () {
|
68 | this.gestute && this.gestute.destroy();
|
69 | this.gestute = null;
|
70 | this.unlisten();
|
71 | this.events.destroy();
|
72 | this.events = this.element = this.gestute = null;
|
73 | };
|
74 | |
75 |
|
76 |
|
77 |
|
78 | PanGesture.prototype.pointerDown = function (ev) {
|
79 | if (this.started) {
|
80 | return;
|
81 | }
|
82 | if (!this.canStart(ev)) {
|
83 | return false;
|
84 | }
|
85 | if (this.gestute) {
|
86 |
|
87 | this.gestute.release();
|
88 |
|
89 | if (!this.gestute.start()) {
|
90 | return false;
|
91 | }
|
92 | }
|
93 | this.started = true;
|
94 | this.captured = false;
|
95 | var coord = pointerCoord(ev);
|
96 | if (this.detector) {
|
97 | this.detector.start(coord);
|
98 | }
|
99 | else {
|
100 | if (!this.tryToCapture(ev)) {
|
101 | this.started = false;
|
102 | this.captured = false;
|
103 | this.gestute.release();
|
104 | return false;
|
105 | }
|
106 | }
|
107 | return true;
|
108 | };
|
109 | |
110 |
|
111 |
|
112 |
|
113 | PanGesture.prototype.pointerMove = function (ev) {
|
114 | var _this = this;
|
115 | (void 0) ;
|
116 | if (this.captured) {
|
117 | this.debouncer.write(function () {
|
118 | _this.onDragMove(ev);
|
119 | });
|
120 | return;
|
121 | }
|
122 | (void 0) ;
|
123 | var coord = pointerCoord(ev);
|
124 | if (this.detector.detect(coord)) {
|
125 | if (this.detector.pan() !== 0) {
|
126 | if (!this.tryToCapture(ev)) {
|
127 | this.abort(ev);
|
128 | }
|
129 | }
|
130 | }
|
131 | };
|
132 | |
133 |
|
134 |
|
135 |
|
136 | PanGesture.prototype.pointerUp = function (ev) {
|
137 | (void 0) ;
|
138 | this.debouncer.cancel();
|
139 | this.gestute && this.gestute.release();
|
140 | if (this.captured) {
|
141 | this.onDragEnd(ev);
|
142 | }
|
143 | else {
|
144 | this.notCaptured(ev);
|
145 | }
|
146 | this.captured = false;
|
147 | this.started = false;
|
148 | };
|
149 | |
150 |
|
151 |
|
152 |
|
153 | PanGesture.prototype.tryToCapture = function (ev) {
|
154 | (void 0) ;
|
155 | (void 0) ;
|
156 | if (this.gestute && !this.gestute.capture()) {
|
157 | return false;
|
158 | }
|
159 | this.onDragStart(ev);
|
160 | this.captured = true;
|
161 | return true;
|
162 | };
|
163 | |
164 |
|
165 |
|
166 |
|
167 | PanGesture.prototype.abort = function (ev) {
|
168 | this.started = false;
|
169 | this.captured = false;
|
170 | this.gestute.release();
|
171 | this.pointerEvents.stop();
|
172 | this.notCaptured(ev);
|
173 | };
|
174 | |
175 |
|
176 |
|
177 | PanGesture.prototype.getNativeElement = function () {
|
178 | return this.element;
|
179 | };
|
180 | |
181 |
|
182 |
|
183 |
|
184 | PanGesture.prototype.canStart = function (_ev) { return true; };
|
185 | |
186 |
|
187 |
|
188 |
|
189 | PanGesture.prototype.onDragStart = function (_ev) { };
|
190 | |
191 |
|
192 |
|
193 |
|
194 | PanGesture.prototype.onDragMove = function (_ev) { };
|
195 | |
196 |
|
197 |
|
198 |
|
199 | PanGesture.prototype.onDragEnd = function (_ev) { };
|
200 | |
201 |
|
202 |
|
203 |
|
204 | PanGesture.prototype.notCaptured = function (_ev) { };
|
205 | return PanGesture;
|
206 | }());
|
207 | export { PanGesture };
|
208 | function PanGesture_tsickle_Closure_declarations() {
|
209 |
|
210 | PanGesture.prototype.debouncer;
|
211 |
|
212 | PanGesture.prototype.events;
|
213 |
|
214 | PanGesture.prototype.pointerEvents;
|
215 |
|
216 | PanGesture.prototype.detector;
|
217 |
|
218 | PanGesture.prototype.started;
|
219 |
|
220 | PanGesture.prototype.captured;
|
221 |
|
222 | PanGesture.prototype.isListening;
|
223 |
|
224 | PanGesture.prototype.gestute;
|
225 |
|
226 | PanGesture.prototype.direction;
|
227 |
|
228 | PanGesture.prototype.eventsConfig;
|
229 |
|
230 | PanGesture.prototype.plt;
|
231 |
|
232 | PanGesture.prototype.element;
|
233 | }
|
234 |
|
\ | No newline at end of file |