devextreme
Version:
HTML5 JavaScript Component Suite for Responsive Web Development
64 lines (63 loc) • 2.01 kB
JavaScript
/**
* DevExtreme (esm/__internal/events/pointer/m_touch.js)
* Version: 24.2.7
* Build date: Mon Apr 28 2025
*
* Copyright (c) 2012 - 2025 Developer Express Inc. ALL RIGHTS RESERVED
* Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/
*/
import BaseStrategy from "../../../common/core/events/pointer/base";
import {
extend
} from "../../../core/utils/extend";
import {
each
} from "../../../core/utils/iterator";
import devices from "../../core/m_devices";
const eventMap = {
dxpointerdown: "touchstart",
dxpointermove: "touchmove",
dxpointerup: "touchend",
dxpointercancel: "touchcancel",
dxpointerover: "",
dxpointerout: "",
dxpointerenter: "",
dxpointerleave: ""
};
const normalizeTouchEvent = function(e) {
const pointers = [];
each(e.touches, ((_, touch) => {
pointers.push(extend({
pointerId: touch.identifier
}, touch))
}));
return {
pointers: pointers,
pointerId: e.changedTouches[0].identifier
}
};
const skipTouchWithSameIdentifier = function(pointerEvent) {
return "ios" === devices.real().platform && ("dxpointerdown" === pointerEvent || "dxpointerup" === pointerEvent)
};
const TouchStrategy = BaseStrategy.inherit({
ctor() {
this.callBase.apply(this, arguments);
this._pointerId = 0
},
_handler(e) {
if (skipTouchWithSameIdentifier(this._eventName)) {
const touch = e.changedTouches[0];
if (this._pointerId === touch.identifier && 0 !== this._pointerId) {
return
}
this._pointerId = touch.identifier
}
return this.callBase.apply(this, arguments)
},
_fireEvent(args) {
return this.callBase(extend(normalizeTouchEvent(args.originalEvent), args))
}
});
TouchStrategy.map = eventMap;
TouchStrategy.normalize = normalizeTouchEvent;
export default TouchStrategy;