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 | function PanGesture(plt, element, opts) {
|
10 | if (opts === void 0) { opts = {}; }
|
11 | this.plt = plt;
|
12 | this.element = element;
|
13 | defaults(opts, {
|
14 | threshold: 20,
|
15 | maxAngle: 40,
|
16 | direction: 'x',
|
17 | zone: true,
|
18 | capture: false,
|
19 | passive: false,
|
20 | });
|
21 | this.events = new UIEventManager(plt);
|
22 | if (opts.domController) {
|
23 | this.debouncer = opts.domController.debouncer();
|
24 | }
|
25 | this.gestute = opts.gesture;
|
26 | this.direction = opts.direction;
|
27 | this.eventsConfig = {
|
28 | element: this.element,
|
29 | pointerDown: this.pointerDown.bind(this),
|
30 | pointerMove: this.pointerMove.bind(this),
|
31 | pointerUp: this.pointerUp.bind(this),
|
32 | zone: opts.zone,
|
33 | capture: opts.capture,
|
34 | passive: opts.passive
|
35 | };
|
36 | if (opts.threshold > 0) {
|
37 | this.detector = new PanRecognizer(opts.direction, opts.threshold, opts.maxAngle);
|
38 | }
|
39 | }
|
40 | PanGesture.prototype.listen = function () {
|
41 | if (!this.isListening) {
|
42 | this.pointerEvents = this.events.pointerEvents(this.eventsConfig);
|
43 | this.isListening = true;
|
44 | }
|
45 | };
|
46 | PanGesture.prototype.unlisten = function () {
|
47 | if (this.isListening) {
|
48 | this.gestute && this.gestute.release();
|
49 | this.events.unlistenAll();
|
50 | this.isListening = false;
|
51 | }
|
52 | };
|
53 | PanGesture.prototype.destroy = function () {
|
54 | this.gestute && this.gestute.destroy();
|
55 | this.gestute = null;
|
56 | this.unlisten();
|
57 | this.events.destroy();
|
58 | this.events = this.element = this.gestute = null;
|
59 | };
|
60 | PanGesture.prototype.pointerDown = function (ev) {
|
61 | if (this.started) {
|
62 | return;
|
63 | }
|
64 | if (!this.canStart(ev)) {
|
65 | return false;
|
66 | }
|
67 | if (this.gestute) {
|
68 |
|
69 | this.gestute.release();
|
70 |
|
71 | if (!this.gestute.start()) {
|
72 | return false;
|
73 | }
|
74 | }
|
75 | this.started = true;
|
76 | this.captured = false;
|
77 | var coord = pointerCoord(ev);
|
78 | if (this.detector) {
|
79 | this.detector.start(coord);
|
80 | }
|
81 | else {
|
82 | if (!this.tryToCapture(ev)) {
|
83 | this.started = false;
|
84 | this.captured = false;
|
85 | this.gestute.release();
|
86 | return false;
|
87 | }
|
88 | }
|
89 | return true;
|
90 | };
|
91 | PanGesture.prototype.pointerMove = function (ev) {
|
92 | var _this = this;
|
93 | (void 0) ;
|
94 | if (this.captured) {
|
95 | this.debouncer.write(function () {
|
96 | _this.onDragMove(ev);
|
97 | });
|
98 | return;
|
99 | }
|
100 | (void 0) ;
|
101 | var coord = pointerCoord(ev);
|
102 | if (this.detector.detect(coord)) {
|
103 | if (this.detector.pan() !== 0) {
|
104 | if (!this.tryToCapture(ev)) {
|
105 | this.abort(ev);
|
106 | }
|
107 | }
|
108 | }
|
109 | };
|
110 | PanGesture.prototype.pointerUp = function (ev) {
|
111 | (void 0) ;
|
112 | this.debouncer.cancel();
|
113 | this.gestute && this.gestute.release();
|
114 | if (this.captured) {
|
115 | this.onDragEnd(ev);
|
116 | }
|
117 | else {
|
118 | this.notCaptured(ev);
|
119 | }
|
120 | this.captured = false;
|
121 | this.started = false;
|
122 | };
|
123 | PanGesture.prototype.tryToCapture = function (ev) {
|
124 | (void 0) ;
|
125 | (void 0) ;
|
126 | if (this.gestute && !this.gestute.capture()) {
|
127 | return false;
|
128 | }
|
129 | this.onDragStart(ev);
|
130 | this.captured = true;
|
131 | return true;
|
132 | };
|
133 | PanGesture.prototype.abort = function (ev) {
|
134 | this.started = false;
|
135 | this.captured = false;
|
136 | this.gestute.release();
|
137 | this.pointerEvents.stop();
|
138 | this.notCaptured(ev);
|
139 | };
|
140 | PanGesture.prototype.getNativeElement = function () {
|
141 | return this.element;
|
142 | };
|
143 |
|
144 | PanGesture.prototype.canStart = function (_ev) { return true; };
|
145 | PanGesture.prototype.onDragStart = function (_ev) { };
|
146 | PanGesture.prototype.onDragMove = function (_ev) { };
|
147 | PanGesture.prototype.onDragEnd = function (_ev) { };
|
148 | PanGesture.prototype.notCaptured = function (_ev) { };
|
149 | return PanGesture;
|
150 | }());
|
151 | export { PanGesture };
|
152 |
|
\ | No newline at end of file |