UNPKG

devextreme

Version:

JavaScript/TypeScript Component Suite for Responsive Web Development

65 lines (64 loc) • 1.97 kB
/** * DevExtreme (esm/__internal/events/pointer/touch.js) * Version: 26.1.6 * Build date: Fri Oct 16 2026 * * Copyright (c) 2012 - 2026 Developer Express Inc. ALL RIGHTS RESERVED * Read about DevExtreme licensing here: https://js.devexpress.com/Licensing/ */ import { extend } from "../../../core/utils/extend"; import { each } from "../../../core/utils/iterator"; import devices from "../../core/devices"; import BaseStrategy from "../../events/pointer/base"; 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) }; class TouchStrategy extends BaseStrategy { constructor(eventName, originalEvents) { super(eventName, originalEvents); 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 super._handler(e) } _fireEvent(args) { const touchEvent = args.originalEvent; return super._fireEvent(extend(normalizeTouchEvent(touchEvent), args)) } } TouchStrategy.map = eventMap; TouchStrategy.normalize = normalizeTouchEvent; export default TouchStrategy;