UNPKG

4.01 kBJavaScriptView Raw
1/**
2 * @hidden
3 */
4var PointerEvents = (function () {
5 function PointerEvents(plt, ele, pointerDown, pointerMove, pointerUp, option) {
6 this.plt = plt;
7 this.ele = ele;
8 this.pointerDown = pointerDown;
9 this.pointerMove = pointerMove;
10 this.pointerUp = pointerUp;
11 this.option = option;
12 this.rmTouchStart = null;
13 this.rmTouchMove = null;
14 this.rmTouchEnd = null;
15 this.rmTouchCancel = null;
16 this.rmMouseStart = null;
17 this.rmMouseMove = null;
18 this.rmMouseUp = null;
19 this.lastTouchEvent = 0;
20 this.mouseWait = 2 * 1000;
21 (void 0) /* assert */;
22 (void 0) /* assert */;
23 this.bindTouchEnd = this.handleTouchEnd.bind(this);
24 this.bindMouseUp = this.handleMouseUp.bind(this);
25 this.rmTouchStart = this.plt.registerListener(ele, 'touchstart', this.handleTouchStart.bind(this), option);
26 this.rmMouseStart = this.plt.registerListener(ele, 'mousedown', this.handleMouseDown.bind(this), option);
27 }
28 PointerEvents.prototype.handleTouchStart = function (ev) {
29 (void 0) /* assert */;
30 (void 0) /* assert */;
31 this.lastTouchEvent = Date.now() + this.mouseWait;
32 this.lastEventType = POINTER_EVENT_TYPE_TOUCH;
33 if (!this.pointerDown(ev, POINTER_EVENT_TYPE_TOUCH)) {
34 return;
35 }
36 if (!this.rmTouchMove && this.pointerMove) {
37 this.rmTouchMove = this.plt.registerListener(this.ele, 'touchmove', this.pointerMove, this.option);
38 }
39 if (!this.rmTouchEnd) {
40 this.rmTouchEnd = this.plt.registerListener(this.ele, 'touchend', this.bindTouchEnd, this.option);
41 }
42 if (!this.rmTouchCancel) {
43 this.rmTouchCancel = this.plt.registerListener(this.ele, 'touchcancel', this.bindTouchEnd, this.option);
44 }
45 };
46 PointerEvents.prototype.handleMouseDown = function (ev) {
47 (void 0) /* assert */;
48 (void 0) /* assert */;
49 if (this.lastTouchEvent > Date.now()) {
50 (void 0) /* console.debug */;
51 return;
52 }
53 this.lastEventType = POINTER_EVENT_TYPE_MOUSE;
54 if (!this.pointerDown(ev, POINTER_EVENT_TYPE_MOUSE)) {
55 return;
56 }
57 if (!this.rmMouseMove && this.pointerMove) {
58 this.rmMouseMove = this.plt.registerListener(this.plt.doc(), 'mousemove', this.pointerMove, this.option);
59 }
60 if (!this.rmMouseUp) {
61 this.rmMouseUp = this.plt.registerListener(this.plt.doc(), 'mouseup', this.bindMouseUp, this.option);
62 }
63 };
64 PointerEvents.prototype.handleTouchEnd = function (ev) {
65 this.stopTouch();
66 this.pointerUp && this.pointerUp(ev, POINTER_EVENT_TYPE_TOUCH);
67 };
68 PointerEvents.prototype.handleMouseUp = function (ev) {
69 this.stopMouse();
70 this.pointerUp && this.pointerUp(ev, POINTER_EVENT_TYPE_MOUSE);
71 };
72 PointerEvents.prototype.stopTouch = function () {
73 this.rmTouchMove && this.rmTouchMove();
74 this.rmTouchEnd && this.rmTouchEnd();
75 this.rmTouchCancel && this.rmTouchCancel();
76 this.rmTouchMove = this.rmTouchEnd = this.rmTouchCancel = null;
77 };
78 PointerEvents.prototype.stopMouse = function () {
79 this.rmMouseMove && this.rmMouseMove();
80 this.rmMouseUp && this.rmMouseUp();
81 this.rmMouseMove = this.rmMouseUp = null;
82 };
83 PointerEvents.prototype.stop = function () {
84 this.stopTouch();
85 this.stopMouse();
86 };
87 PointerEvents.prototype.destroy = function () {
88 this.rmTouchStart && this.rmTouchStart();
89 this.rmMouseStart && this.rmMouseStart();
90 this.stop();
91 this.ele = this.pointerUp = this.pointerMove = this.pointerDown = this.rmTouchStart = this.rmMouseStart = null;
92 };
93 return PointerEvents;
94}());
95export { PointerEvents };
96export var POINTER_EVENT_TYPE_MOUSE = 1;
97export var POINTER_EVENT_TYPE_TOUCH = 2;
98//# sourceMappingURL=pointer-events.js.map
\No newline at end of file