UNPKG

devextreme

Version:

HTML5 JavaScript Component Suite for Responsive Web Development

111 lines (110 loc) 3.42 kB
/** * DevExtreme (esm/__internal/events/gesture/m_swipeable.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 _extends from "@babel/runtime/helpers/esm/extends"; import eventsEngine from "../../../common/core/events/core/events_engine"; import { end as swipeEventEnd, start as swipeEventStart, swipe as swipeEventSwipe } from "../../../common/core/events/swipe"; import { addNamespace } from "../../../common/core/events/utils/index"; import { each } from "../../../core/utils/iterator"; import { name } from "../../../core/utils/public_component"; import DOMComponent from "../../core/widget/dom_component"; const DX_SWIPEABLE = "dxSwipeable"; const SWIPEABLE_CLASS = "dx-swipeable"; const ACTION_TO_EVENT_MAP = { onStart: swipeEventStart, onUpdated: swipeEventSwipe, onEnd: swipeEventEnd, onCancel: "dxswipecancel" }; const IMMEDIATE_TIMEOUT = 180; class Swipeable extends DOMComponent { _getDefaultOptions() { return _extends({}, super._getDefaultOptions(), { elastic: true, immediate: false, immediateTimeout: 180, direction: "horizontal", itemSizeFunc: null, onStart: null, onUpdated: null, onEnd: null, onCancel: null }) } _render() { super._render(); this.$element().addClass("dx-swipeable"); this._attachEventHandlers() } _attachEventHandlers() { this._detachEventHandlers(); if (this.option("disabled")) { return } const { NAME: NAME } = this; this._createEventData(); each(ACTION_TO_EVENT_MAP, ((actionName, eventName) => { const action = this._createActionByOption(actionName, { context: this }); eventName = addNamespace(eventName, NAME); eventsEngine.on(this.$element(), eventName, this._eventData, (e => action({ event: e }))) })) } _createEventData() { this._eventData = { elastic: this.option("elastic"), itemSizeFunc: this.option("itemSizeFunc"), direction: this.option("direction"), immediate: this.option("immediate"), immediateTimeout: this.option("immediateTimeout") } } _detachEventHandlers() { eventsEngine.off(this.$element(), `.${DX_SWIPEABLE}`) } _optionChanged(args) { switch (args.name) { case "disabled": case "onStart": case "onUpdated": case "onEnd": case "onCancel": case "elastic": case "immediate": case "itemSizeFunc": case "direction": this._detachEventHandlers(); this._attachEventHandlers(); break; case "rtlEnabled": break; default: super._optionChanged(args) } } _useTemplates() { return false } } name(Swipeable, DX_SWIPEABLE); export default Swipeable;