pointer-events.js 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. (function (factory) {
  2. if (typeof module === "object" && typeof module.exports === "object") {
  3. var v = factory(require, exports);
  4. if (v !== undefined) module.exports = v;
  5. }
  6. else if (typeof define === "function" && define.amd) {
  7. define(["require", "exports"], factory);
  8. }
  9. })(function (require, exports) {
  10. "use strict";
  11. Object.defineProperty(exports, "__esModule", { value: true });
  12. /**
  13. * @hidden
  14. */
  15. var PointerEvents = (function () {
  16. function PointerEvents(plt, ele, pointerDown, pointerMove, pointerUp, option) {
  17. this.plt = plt;
  18. this.ele = ele;
  19. this.pointerDown = pointerDown;
  20. this.pointerMove = pointerMove;
  21. this.pointerUp = pointerUp;
  22. this.option = option;
  23. this.rmTouchStart = null;
  24. this.rmTouchMove = null;
  25. this.rmTouchEnd = null;
  26. this.rmTouchCancel = null;
  27. this.rmMouseStart = null;
  28. this.rmMouseMove = null;
  29. this.rmMouseUp = null;
  30. this.lastTouchEvent = 0;
  31. this.mouseWait = 2 * 1000;
  32. (void 0) /* assert */;
  33. (void 0) /* assert */;
  34. this.bindTouchEnd = this.handleTouchEnd.bind(this);
  35. this.bindMouseUp = this.handleMouseUp.bind(this);
  36. this.rmTouchStart = this.plt.registerListener(ele, 'touchstart', this.handleTouchStart.bind(this), option);
  37. this.rmMouseStart = this.plt.registerListener(ele, 'mousedown', this.handleMouseDown.bind(this), option);
  38. }
  39. PointerEvents.prototype.handleTouchStart = function (ev) {
  40. (void 0) /* assert */;
  41. (void 0) /* assert */;
  42. this.lastTouchEvent = Date.now() + this.mouseWait;
  43. this.lastEventType = exports.POINTER_EVENT_TYPE_TOUCH;
  44. if (!this.pointerDown(ev, exports.POINTER_EVENT_TYPE_TOUCH)) {
  45. return;
  46. }
  47. if (!this.rmTouchMove && this.pointerMove) {
  48. this.rmTouchMove = this.plt.registerListener(this.ele, 'touchmove', this.pointerMove, this.option);
  49. }
  50. if (!this.rmTouchEnd) {
  51. this.rmTouchEnd = this.plt.registerListener(this.ele, 'touchend', this.bindTouchEnd, this.option);
  52. }
  53. if (!this.rmTouchCancel) {
  54. this.rmTouchCancel = this.plt.registerListener(this.ele, 'touchcancel', this.bindTouchEnd, this.option);
  55. }
  56. };
  57. PointerEvents.prototype.handleMouseDown = function (ev) {
  58. (void 0) /* assert */;
  59. (void 0) /* assert */;
  60. if (this.lastTouchEvent > Date.now()) {
  61. (void 0) /* console.debug */;
  62. return;
  63. }
  64. this.lastEventType = exports.POINTER_EVENT_TYPE_MOUSE;
  65. if (!this.pointerDown(ev, exports.POINTER_EVENT_TYPE_MOUSE)) {
  66. return;
  67. }
  68. if (!this.rmMouseMove && this.pointerMove) {
  69. this.rmMouseMove = this.plt.registerListener(this.plt.doc(), 'mousemove', this.pointerMove, this.option);
  70. }
  71. if (!this.rmMouseUp) {
  72. this.rmMouseUp = this.plt.registerListener(this.plt.doc(), 'mouseup', this.bindMouseUp, this.option);
  73. }
  74. };
  75. PointerEvents.prototype.handleTouchEnd = function (ev) {
  76. this.stopTouch();
  77. this.pointerUp && this.pointerUp(ev, exports.POINTER_EVENT_TYPE_TOUCH);
  78. };
  79. PointerEvents.prototype.handleMouseUp = function (ev) {
  80. this.stopMouse();
  81. this.pointerUp && this.pointerUp(ev, exports.POINTER_EVENT_TYPE_MOUSE);
  82. };
  83. PointerEvents.prototype.stopTouch = function () {
  84. this.rmTouchMove && this.rmTouchMove();
  85. this.rmTouchEnd && this.rmTouchEnd();
  86. this.rmTouchCancel && this.rmTouchCancel();
  87. this.rmTouchMove = this.rmTouchEnd = this.rmTouchCancel = null;
  88. };
  89. PointerEvents.prototype.stopMouse = function () {
  90. this.rmMouseMove && this.rmMouseMove();
  91. this.rmMouseUp && this.rmMouseUp();
  92. this.rmMouseMove = this.rmMouseUp = null;
  93. };
  94. PointerEvents.prototype.stop = function () {
  95. this.stopTouch();
  96. this.stopMouse();
  97. };
  98. PointerEvents.prototype.destroy = function () {
  99. this.rmTouchStart && this.rmTouchStart();
  100. this.rmMouseStart && this.rmMouseStart();
  101. this.stop();
  102. this.ele = this.pointerUp = this.pointerMove = this.pointerDown = this.rmTouchStart = this.rmMouseStart = null;
  103. };
  104. return PointerEvents;
  105. }());
  106. exports.PointerEvents = PointerEvents;
  107. exports.POINTER_EVENT_TYPE_MOUSE = 1;
  108. exports.POINTER_EVENT_TYPE_TOUCH = 2;
  109. });
  110. //# sourceMappingURL=pointer-events.js.map