UNPKG

5.74 kBJavaScriptView Raw
1/**
2 * @hidden
3 */
4var PointerEvents = (function () {
5 /**
6 * @param {?} plt
7 * @param {?} ele
8 * @param {?} pointerDown
9 * @param {?} pointerMove
10 * @param {?} pointerUp
11 * @param {?} option
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) /* assert */;
30 (void 0) /* assert */;
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 * @param {?} ev
38 * @return {?}
39 */
40 PointerEvents.prototype.handleTouchStart = function (ev) {
41 (void 0) /* assert */;
42 (void 0) /* assert */;
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 * @param {?} ev
60 * @return {?}
61 */
62 PointerEvents.prototype.handleMouseDown = function (ev) {
63 (void 0) /* assert */;
64 (void 0) /* assert */;
65 if (this.lastTouchEvent > Date.now()) {
66 (void 0) /* console.debug */;
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 * @param {?} ev
82 * @return {?}
83 */
84 PointerEvents.prototype.handleTouchEnd = function (ev) {
85 this.stopTouch();
86 this.pointerUp && this.pointerUp(ev, POINTER_EVENT_TYPE_TOUCH);
87 };
88 /**
89 * @param {?} ev
90 * @return {?}
91 */
92 PointerEvents.prototype.handleMouseUp = function (ev) {
93 this.stopMouse();
94 this.pointerUp && this.pointerUp(ev, POINTER_EVENT_TYPE_MOUSE);
95 };
96 /**
97 * @return {?}
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 * @return {?}
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 * @return {?}
115 */
116 PointerEvents.prototype.stop = function () {
117 this.stopTouch();
118 this.stopMouse();
119 };
120 /**
121 * @return {?}
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}());
131export { PointerEvents };
132function PointerEvents_tsickle_Closure_declarations() {
133 /** @type {?} */
134 PointerEvents.prototype.rmTouchStart;
135 /** @type {?} */
136 PointerEvents.prototype.rmTouchMove;
137 /** @type {?} */
138 PointerEvents.prototype.rmTouchEnd;
139 /** @type {?} */
140 PointerEvents.prototype.rmTouchCancel;
141 /** @type {?} */
142 PointerEvents.prototype.rmMouseStart;
143 /** @type {?} */
144 PointerEvents.prototype.rmMouseMove;
145 /** @type {?} */
146 PointerEvents.prototype.rmMouseUp;
147 /** @type {?} */
148 PointerEvents.prototype.bindTouchEnd;
149 /** @type {?} */
150 PointerEvents.prototype.bindMouseUp;
151 /** @type {?} */
152 PointerEvents.prototype.lastTouchEvent;
153 /** @type {?} */
154 PointerEvents.prototype.mouseWait;
155 /** @type {?} */
156 PointerEvents.prototype.lastEventType;
157 /** @type {?} */
158 PointerEvents.prototype.plt;
159 /** @type {?} */
160 PointerEvents.prototype.ele;
161 /** @type {?} */
162 PointerEvents.prototype.pointerDown;
163 /** @type {?} */
164 PointerEvents.prototype.pointerMove;
165 /** @type {?} */
166 PointerEvents.prototype.pointerUp;
167 /** @type {?} */
168 PointerEvents.prototype.option;
169}
170export var /** @type {?} */ POINTER_EVENT_TYPE_MOUSE = 1;
171export var /** @type {?} */ POINTER_EVENT_TYPE_TOUCH = 2;
172//# sourceMappingURL=pointer-events.js.map
\No newline at end of file