123456789101112131415161718192021222324252627282930313233343536373839404142 |
- "use strict";
- Object.defineProperty(exports, "__esModule", { value: true });
- var DomEventAware = (function () {
- function DomEventAware() {
- this.x = 0;
- this.y = 0;
- this.previousMouseX = 0;
- this.previousMouseY = 0;
- }
- DomEventAware.prototype.init = function (ele) {
- ele.addEventListener('mousedown', this.onMouseDown);
- ele.addEventListener('mouseup', this.onMouseUp);
- ele.addEventListener('mousemove', this.onMouseMove);
- ele.addEventListener('touchstart', this.onTouch, { passive: false });
- ele.addEventListener('touchend', this.onTouch, { passive: false });
- ele.addEventListener('touchmove', this.onTouch, { passive: false });
- };
- DomEventAware.prototype.onTouch = function (ev) {
- ev.preventDefault();
- var newEvt = document.createEvent('MouseEvents');
- var touch = ev.changedTouches[0];
- var type = null;
- switch (ev.type) {
- case 'touchstart':
- type = 'mousedown';
- break;
- case 'touchmove':
- type = 'mousemove';
- break;
- case 'touchend':
- type = 'mouseup';
- break;
- default:
- break;
- }
- 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);
- ev.target.dispatchEvent(newEvt);
- };
- return DomEventAware;
- }());
- exports.DomEventAware = DomEventAware;
|