No Description

index.js 1.5KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", { value: true });
  3. var DomEventAware = (function () {
  4. function DomEventAware() {
  5. this.x = 0;
  6. this.y = 0;
  7. this.previousMouseX = 0;
  8. this.previousMouseY = 0;
  9. }
  10. DomEventAware.prototype.init = function (ele) {
  11. ele.addEventListener('mousedown', this.onMouseDown);
  12. ele.addEventListener('mouseup', this.onMouseUp);
  13. ele.addEventListener('mousemove', this.onMouseMove);
  14. ele.addEventListener('touchstart', this.onTouch, { passive: false });
  15. ele.addEventListener('touchend', this.onTouch, { passive: false });
  16. ele.addEventListener('touchmove', this.onTouch, { passive: false });
  17. };
  18. DomEventAware.prototype.onTouch = function (ev) {
  19. ev.preventDefault();
  20. var newEvt = document.createEvent('MouseEvents');
  21. var touch = ev.changedTouches[0];
  22. var type = null;
  23. switch (ev.type) {
  24. case 'touchstart':
  25. type = 'mousedown';
  26. break;
  27. case 'touchmove':
  28. type = 'mousemove';
  29. break;
  30. case 'touchend':
  31. type = 'mouseup';
  32. break;
  33. default:
  34. break;
  35. }
  36. newEvt.initMouseEvent(type, true, true, window, 0, touch.screenX, touch.screenY, touch.clientX, touch.clientY, ev.ctrlKey, ev.altKey, ev.shiftKey, ev.metaKey, 0, null);
  37. ev.target.dispatchEvent(newEvt);
  38. };
  39. return DomEventAware;
  40. }());
  41. exports.DomEventAware = DomEventAware;