1 |
|
2 |
|
3 |
|
4 | var PointerEvents = (function () {
|
5 | |
6 |
|
7 |
|
8 |
|
9 |
|
10 |
|
11 |
|
12 |
|
13 | function PointerEvents(plt, ele, pointerDown, pointerMove, pointerUp, option) {
|
14 | this.plt = plt;
|
15 | this.ele = ele;
|
16 | this.pointerDown = pointerDown;
|
17 | this.pointerMove = pointerMove;
|
18 | this.pointerUp = pointerUp;
|
19 | this.option = option;
|
20 | this.rmTouchStart = null;
|
21 | this.rmTouchMove = null;
|
22 | this.rmTouchEnd = null;
|
23 | this.rmTouchCancel = null;
|
24 | this.rmMouseStart = null;
|
25 | this.rmMouseMove = null;
|
26 | this.rmMouseUp = null;
|
27 | this.lastTouchEvent = 0;
|
28 | this.mouseWait = 2 * 1000;
|
29 | (void 0) ;
|
30 | (void 0) ;
|
31 | this.bindTouchEnd = this.handleTouchEnd.bind(this);
|
32 | this.bindMouseUp = this.handleMouseUp.bind(this);
|
33 | this.rmTouchStart = this.plt.registerListener(ele, 'touchstart', this.handleTouchStart.bind(this), option);
|
34 | this.rmMouseStart = this.plt.registerListener(ele, 'mousedown', this.handleMouseDown.bind(this), option);
|
35 | }
|
36 | |
37 |
|
38 |
|
39 |
|
40 | PointerEvents.prototype.handleTouchStart = function (ev) {
|
41 | (void 0) ;
|
42 | (void 0) ;
|
43 | this.lastTouchEvent = Date.now() + this.mouseWait;
|
44 | this.lastEventType = POINTER_EVENT_TYPE_TOUCH;
|
45 | if (!this.pointerDown(ev, POINTER_EVENT_TYPE_TOUCH)) {
|
46 | return;
|
47 | }
|
48 | if (!this.rmTouchMove && this.pointerMove) {
|
49 | this.rmTouchMove = this.plt.registerListener(this.ele, 'touchmove', this.pointerMove, this.option);
|
50 | }
|
51 | if (!this.rmTouchEnd) {
|
52 | this.rmTouchEnd = this.plt.registerListener(this.ele, 'touchend', this.bindTouchEnd, this.option);
|
53 | }
|
54 | if (!this.rmTouchCancel) {
|
55 | this.rmTouchCancel = this.plt.registerListener(this.ele, 'touchcancel', this.bindTouchEnd, this.option);
|
56 | }
|
57 | };
|
58 | |
59 |
|
60 |
|
61 |
|
62 | PointerEvents.prototype.handleMouseDown = function (ev) {
|
63 | (void 0) ;
|
64 | (void 0) ;
|
65 | if (this.lastTouchEvent > Date.now()) {
|
66 | (void 0) ;
|
67 | return;
|
68 | }
|
69 | this.lastEventType = POINTER_EVENT_TYPE_MOUSE;
|
70 | if (!this.pointerDown(ev, POINTER_EVENT_TYPE_MOUSE)) {
|
71 | return;
|
72 | }
|
73 | if (!this.rmMouseMove && this.pointerMove) {
|
74 | this.rmMouseMove = this.plt.registerListener(this.plt.doc(), 'mousemove', this.pointerMove, this.option);
|
75 | }
|
76 | if (!this.rmMouseUp) {
|
77 | this.rmMouseUp = this.plt.registerListener(this.plt.doc(), 'mouseup', this.bindMouseUp, this.option);
|
78 | }
|
79 | };
|
80 | |
81 |
|
82 |
|
83 |
|
84 | PointerEvents.prototype.handleTouchEnd = function (ev) {
|
85 | this.stopTouch();
|
86 | this.pointerUp && this.pointerUp(ev, POINTER_EVENT_TYPE_TOUCH);
|
87 | };
|
88 | |
89 |
|
90 |
|
91 |
|
92 | PointerEvents.prototype.handleMouseUp = function (ev) {
|
93 | this.stopMouse();
|
94 | this.pointerUp && this.pointerUp(ev, POINTER_EVENT_TYPE_MOUSE);
|
95 | };
|
96 | |
97 |
|
98 |
|
99 | PointerEvents.prototype.stopTouch = function () {
|
100 | this.rmTouchMove && this.rmTouchMove();
|
101 | this.rmTouchEnd && this.rmTouchEnd();
|
102 | this.rmTouchCancel && this.rmTouchCancel();
|
103 | this.rmTouchMove = this.rmTouchEnd = this.rmTouchCancel = null;
|
104 | };
|
105 | |
106 |
|
107 |
|
108 | PointerEvents.prototype.stopMouse = function () {
|
109 | this.rmMouseMove && this.rmMouseMove();
|
110 | this.rmMouseUp && this.rmMouseUp();
|
111 | this.rmMouseMove = this.rmMouseUp = null;
|
112 | };
|
113 | |
114 |
|
115 |
|
116 | PointerEvents.prototype.stop = function () {
|
117 | this.stopTouch();
|
118 | this.stopMouse();
|
119 | };
|
120 | |
121 |
|
122 |
|
123 | PointerEvents.prototype.destroy = function () {
|
124 | this.rmTouchStart && this.rmTouchStart();
|
125 | this.rmMouseStart && this.rmMouseStart();
|
126 | this.stop();
|
127 | this.ele = this.pointerUp = this.pointerMove = this.pointerDown = this.rmTouchStart = this.rmMouseStart = null;
|
128 | };
|
129 | return PointerEvents;
|
130 | }());
|
131 | export { PointerEvents };
|
132 | function PointerEvents_tsickle_Closure_declarations() {
|
133 |
|
134 | PointerEvents.prototype.rmTouchStart;
|
135 |
|
136 | PointerEvents.prototype.rmTouchMove;
|
137 |
|
138 | PointerEvents.prototype.rmTouchEnd;
|
139 |
|
140 | PointerEvents.prototype.rmTouchCancel;
|
141 |
|
142 | PointerEvents.prototype.rmMouseStart;
|
143 |
|
144 | PointerEvents.prototype.rmMouseMove;
|
145 |
|
146 | PointerEvents.prototype.rmMouseUp;
|
147 |
|
148 | PointerEvents.prototype.bindTouchEnd;
|
149 |
|
150 | PointerEvents.prototype.bindMouseUp;
|
151 |
|
152 | PointerEvents.prototype.lastTouchEvent;
|
153 |
|
154 | PointerEvents.prototype.mouseWait;
|
155 |
|
156 | PointerEvents.prototype.lastEventType;
|
157 |
|
158 | PointerEvents.prototype.plt;
|
159 |
|
160 | PointerEvents.prototype.ele;
|
161 |
|
162 | PointerEvents.prototype.pointerDown;
|
163 |
|
164 | PointerEvents.prototype.pointerMove;
|
165 |
|
166 | PointerEvents.prototype.pointerUp;
|
167 |
|
168 | PointerEvents.prototype.option;
|
169 | }
|
170 | export var POINTER_EVENT_TYPE_MOUSE = 1;
|
171 | export var POINTER_EVENT_TYPE_TOUCH = 2;
|
172 |
|
\ | No newline at end of file |