1 | import { Inject, Injectable, forwardRef } from '@angular/core';
|
2 | import { App } from '../components/app/app';
|
3 |
|
4 |
|
5 |
|
6 | export var GESTURE_GO_BACK_SWIPE = 'goback-swipe';
|
7 |
|
8 |
|
9 |
|
10 | export var GESTURE_MENU_SWIPE = 'menu-swipe';
|
11 |
|
12 |
|
13 |
|
14 | export var GESTURE_ITEM_SWIPE = 'item-swipe';
|
15 |
|
16 |
|
17 |
|
18 | export var GESTURE_REFRESHER = 'refresher';
|
19 |
|
20 |
|
21 |
|
22 | export var GESTURE_TOGGLE = 'toggle';
|
23 |
|
24 |
|
25 |
|
26 | export var GESTURE_PRIORITY_SLIDING_ITEM = -10;
|
27 |
|
28 |
|
29 |
|
30 | export var GESTURE_PRIORITY_REFRESHER = 0;
|
31 |
|
32 |
|
33 |
|
34 | export var GESTURE_PRIORITY_MENU_SWIPE = 10;
|
35 |
|
36 |
|
37 |
|
38 | export var GESTURE_PRIORITY_GO_BACK_SWIPE = 20;
|
39 |
|
40 |
|
41 |
|
42 | export var GESTURE_PRIORITY_TOGGLE = 30;
|
43 |
|
44 |
|
45 |
|
46 | export var BLOCK_ALL = {
|
47 | disable: [GESTURE_MENU_SWIPE, GESTURE_GO_BACK_SWIPE],
|
48 | disableScroll: true
|
49 | };
|
50 |
|
51 |
|
52 |
|
53 | var GestureController = (function () {
|
54 | |
55 |
|
56 |
|
57 | function GestureController(_app) {
|
58 | this._app = _app;
|
59 | this.id = 1;
|
60 | this.requestedStart = {};
|
61 | this.disabledGestures = {};
|
62 | this.disabledScroll = new Set();
|
63 | this.capturedID = null;
|
64 | }
|
65 | |
66 |
|
67 |
|
68 |
|
69 | GestureController.prototype.createGesture = function (opts) {
|
70 | if (!opts.name) {
|
71 | throw new Error('name is undefined');
|
72 | }
|
73 | return new GestureDelegate(opts.name, this.newID(), this, opts.priority || 0, !!opts.disableScroll);
|
74 | };
|
75 | |
76 |
|
77 |
|
78 |
|
79 | GestureController.prototype.createBlocker = function (opts) {
|
80 | if (opts === void 0) { opts = {}; }
|
81 | return new BlockerDelegate(this.newID(), this, opts.disable, !!opts.disableScroll);
|
82 | };
|
83 | |
84 |
|
85 |
|
86 | GestureController.prototype.newID = function () {
|
87 | var id = this.id;
|
88 | this.id++;
|
89 | return id;
|
90 | };
|
91 | |
92 |
|
93 |
|
94 |
|
95 |
|
96 |
|
97 | GestureController.prototype.start = function (gestureName, id, priority) {
|
98 | if (!this.canStart(gestureName)) {
|
99 | delete this.requestedStart[id];
|
100 | return false;
|
101 | }
|
102 | this.requestedStart[id] = priority;
|
103 | return true;
|
104 | };
|
105 | |
106 |
|
107 |
|
108 |
|
109 |
|
110 |
|
111 | GestureController.prototype.capture = function (gestureName, id, priority) {
|
112 | if (!this.start(gestureName, id, priority)) {
|
113 | return false;
|
114 | }
|
115 | var requestedStart = this.requestedStart;
|
116 | var maxPriority = -10000;
|
117 | for (var gestureID in requestedStart) {
|
118 | maxPriority = Math.max(maxPriority, requestedStart[gestureID]);
|
119 | }
|
120 | if (maxPriority === priority) {
|
121 | this.capturedID = id;
|
122 | this.requestedStart = {};
|
123 | (void 0) ;
|
124 | return true;
|
125 | }
|
126 | delete requestedStart[id];
|
127 | (void 0) ;
|
128 | return false;
|
129 | };
|
130 | |
131 |
|
132 |
|
133 |
|
134 | GestureController.prototype.release = function (id) {
|
135 | delete this.requestedStart[id];
|
136 | if (this.capturedID && id === this.capturedID) {
|
137 | this.capturedID = null;
|
138 | }
|
139 | };
|
140 | |
141 |
|
142 |
|
143 |
|
144 |
|
145 | GestureController.prototype.disableGesture = function (gestureName, id) {
|
146 | var set = this.disabledGestures[gestureName];
|
147 | if (!set) {
|
148 | set = new Set();
|
149 | this.disabledGestures[gestureName] = set;
|
150 | }
|
151 | set.add(id);
|
152 | };
|
153 | /**
|
154 | * @param {?} gestureName
|
155 | * @param {?} id
|
156 | * @return {?}
|
157 | */
|
158 | GestureController.prototype.enableGesture = function (gestureName, id) {
|
159 | var set = this.disabledGestures[gestureName];
|
160 | if (set) {
|
161 | set.delete(id);
|
162 | }
|
163 | };
|
164 | /**
|
165 | * @param {?} id
|
166 | * @return {?}
|
167 | */
|
168 | GestureController.prototype.disableScroll = function (id) {
|
169 | var isEnabled = !this.isScrollDisabled();
|
170 | this.disabledScroll.add(id);
|
171 | if (this._app && isEnabled && this.isScrollDisabled()) {
|
172 | (void 0) ;
|
173 | this._app._setDisableScroll(true);
|
174 | }
|
175 | };
|
176 | |
177 |
|
178 |
|
179 |
|
180 | GestureController.prototype.enableScroll = function (id) {
|
181 | var isDisabled = this.isScrollDisabled();
|
182 | this.disabledScroll.delete(id);
|
183 | if (this._app && isDisabled && !this.isScrollDisabled()) {
|
184 | (void 0) ;
|
185 | this._app._setDisableScroll(false);
|
186 | }
|
187 | };
|
188 | |
189 |
|
190 |
|
191 |
|
192 | GestureController.prototype.canStart = function (gestureName) {
|
193 | if (this.capturedID) {
|
194 | (void 0) ;
|
195 |
|
196 | return false;
|
197 | }
|
198 | if (this.isDisabled(gestureName)) {
|
199 | (void 0) ;
|
200 | return false;
|
201 | }
|
202 | return true;
|
203 | };
|
204 | |
205 |
|
206 |
|
207 | GestureController.prototype.isCaptured = function () {
|
208 | return !!this.capturedID;
|
209 | };
|
210 | |
211 |
|
212 |
|
213 | GestureController.prototype.isScrollDisabled = function () {
|
214 | return this.disabledScroll.size > 0;
|
215 | };
|
216 | |
217 |
|
218 |
|
219 |
|
220 | GestureController.prototype.isDisabled = function (gestureName) {
|
221 | var disabled = this.disabledGestures[gestureName];
|
222 | return !!(disabled && disabled.size > 0);
|
223 | };
|
224 | return GestureController;
|
225 | }());
|
226 | export { GestureController };
|
227 | GestureController.decorators = [
|
228 | { type: Injectable },
|
229 | ];
|
230 |
|
231 |
|
232 |
|
233 | GestureController.ctorParameters = function () { return [
|
234 | { type: App, decorators: [{ type: Inject, args: [forwardRef(function () { return App; }),] },] },
|
235 | ]; };
|
236 | function GestureController_tsickle_Closure_declarations() {
|
237 |
|
238 | GestureController.decorators;
|
239 | |
240 |
|
241 |
|
242 |
|
243 | GestureController.ctorParameters;
|
244 |
|
245 | GestureController.prototype.id;
|
246 |
|
247 | GestureController.prototype.requestedStart;
|
248 |
|
249 | GestureController.prototype.disabledGestures;
|
250 |
|
251 | GestureController.prototype.disabledScroll;
|
252 |
|
253 | GestureController.prototype.capturedID;
|
254 |
|
255 | GestureController.prototype._app;
|
256 | }
|
257 |
|
258 |
|
259 |
|
260 | var GestureDelegate = (function () {
|
261 | |
262 |
|
263 |
|
264 |
|
265 |
|
266 |
|
267 |
|
268 | function GestureDelegate(name, id, controller, priority, disableScroll) {
|
269 | this.name = name;
|
270 | this.id = id;
|
271 | this.controller = controller;
|
272 | this.priority = priority;
|
273 | this.disableScroll = disableScroll;
|
274 | }
|
275 | |
276 |
|
277 |
|
278 | GestureDelegate.prototype.canStart = function () {
|
279 | if (!this.controller) {
|
280 | (void 0) ;
|
281 | return false;
|
282 | }
|
283 | return this.controller.canStart(this.name);
|
284 | };
|
285 | |
286 |
|
287 |
|
288 | GestureDelegate.prototype.start = function () {
|
289 | if (!this.controller) {
|
290 | (void 0) ;
|
291 | return false;
|
292 | }
|
293 | return this.controller.start(this.name, this.id, this.priority);
|
294 | };
|
295 | |
296 |
|
297 |
|
298 | GestureDelegate.prototype.capture = function () {
|
299 | if (!this.controller) {
|
300 | (void 0) ;
|
301 | return false;
|
302 | }
|
303 | var captured = this.controller.capture(this.name, this.id, this.priority);
|
304 | if (captured && this.disableScroll) {
|
305 | this.controller.disableScroll(this.id);
|
306 | }
|
307 | return captured;
|
308 | };
|
309 | |
310 |
|
311 |
|
312 | GestureDelegate.prototype.release = function () {
|
313 | if (!this.controller) {
|
314 | (void 0) ;
|
315 | return;
|
316 | }
|
317 | this.controller.release(this.id);
|
318 | if (this.disableScroll) {
|
319 | this.controller.enableScroll(this.id);
|
320 | }
|
321 | };
|
322 | |
323 |
|
324 |
|
325 | GestureDelegate.prototype.destroy = function () {
|
326 | this.release();
|
327 | this.controller = null;
|
328 | };
|
329 | return GestureDelegate;
|
330 | }());
|
331 | export { GestureDelegate };
|
332 | function GestureDelegate_tsickle_Closure_declarations() {
|
333 |
|
334 | GestureDelegate.prototype.name;
|
335 |
|
336 | GestureDelegate.prototype.id;
|
337 |
|
338 | GestureDelegate.prototype.controller;
|
339 |
|
340 | GestureDelegate.prototype.priority;
|
341 |
|
342 | GestureDelegate.prototype.disableScroll;
|
343 | }
|
344 |
|
345 |
|
346 |
|
347 | var BlockerDelegate = (function () {
|
348 | |
349 |
|
350 |
|
351 |
|
352 |
|
353 |
|
354 | function BlockerDelegate(id, controller, disable, disableScroll) {
|
355 | this.id = id;
|
356 | this.controller = controller;
|
357 | this.disable = disable;
|
358 | this.disableScroll = disableScroll;
|
359 | this.blocked = false;
|
360 | }
|
361 | |
362 |
|
363 |
|
364 | BlockerDelegate.prototype.block = function () {
|
365 | var _this = this;
|
366 | if (!this.controller) {
|
367 | (void 0) ;
|
368 | return;
|
369 | }
|
370 | if (this.disable) {
|
371 | this.disable.forEach(function (gesture) {
|
372 | _this.controller.disableGesture(gesture, _this.id);
|
373 | });
|
374 | }
|
375 | if (this.disableScroll) {
|
376 | this.controller.disableScroll(this.id);
|
377 | }
|
378 | this.blocked = true;
|
379 | };
|
380 | |
381 |
|
382 |
|
383 | BlockerDelegate.prototype.unblock = function () {
|
384 | var _this = this;
|
385 | if (!this.controller) {
|
386 | (void 0) ;
|
387 | return;
|
388 | }
|
389 | if (this.disable) {
|
390 | this.disable.forEach(function (gesture) {
|
391 | _this.controller.enableGesture(gesture, _this.id);
|
392 | });
|
393 | }
|
394 | if (this.disableScroll) {
|
395 | this.controller.enableScroll(this.id);
|
396 | }
|
397 | this.blocked = false;
|
398 | };
|
399 | |
400 |
|
401 |
|
402 | BlockerDelegate.prototype.destroy = function () {
|
403 | this.unblock();
|
404 | this.controller = null;
|
405 | };
|
406 | return BlockerDelegate;
|
407 | }());
|
408 | export { BlockerDelegate };
|
409 | function BlockerDelegate_tsickle_Closure_declarations() {
|
410 |
|
411 | BlockerDelegate.prototype.blocked;
|
412 |
|
413 | BlockerDelegate.prototype.id;
|
414 |
|
415 | BlockerDelegate.prototype.controller;
|
416 |
|
417 | BlockerDelegate.prototype.disable;
|
418 |
|
419 | BlockerDelegate.prototype.disableScroll;
|
420 | }
|
421 |
|
\ | No newline at end of file |