aboutsummaryrefslogtreecommitdiff
path: root/js/dist/util/swipe.js
diff options
context:
space:
mode:
authorBobby <[email protected]>2024-08-16 20:47:33 -0400
committerGitHub <[email protected]>2024-08-16 20:47:33 -0400
commit6b28433d9cfde435be8ec2bd6cf91e6324d08865 (patch)
tree8343c27b8b95ff5639233e81cf157f92e5688466 /js/dist/util/swipe.js
parentd53094ec16ba385faae2973ddee648698b32ab24 (diff)
parent048f56f51460df75e92a2f7b472e1c56baeb68f7 (diff)
downloadbootstrap-main.tar.xz
bootstrap-main.zip
Merge branch 'twbs:main' into mainHEADmain
Diffstat (limited to 'js/dist/util/swipe.js')
-rw-r--r--js/dist/util/swipe.js135
1 files changed, 135 insertions, 0 deletions
diff --git a/js/dist/util/swipe.js b/js/dist/util/swipe.js
new file mode 100644
index 000000000..f99fd1906
--- /dev/null
+++ b/js/dist/util/swipe.js
@@ -0,0 +1,135 @@
+/*!
+ * Bootstrap swipe.js v5.3.3 (https://getbootstrap.com/)
+ * Copyright 2011-2024 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
+ */
+(function (global, factory) {
+ typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/event-handler.js'), require('./config.js'), require('./index.js')) :
+ typeof define === 'function' && define.amd ? define(['../dom/event-handler', './config', './index'], factory) :
+ (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Swipe = factory(global.EventHandler, global.Config, global.Index));
+})(this, (function (EventHandler, Config, index_js) { 'use strict';
+
+ /**
+ * --------------------------------------------------------------------------
+ * Bootstrap util/swipe.js
+ * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
+ * --------------------------------------------------------------------------
+ */
+
+
+ /**
+ * Constants
+ */
+
+ const NAME = 'swipe';
+ const EVENT_KEY = '.bs.swipe';
+ const EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`;
+ const EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`;
+ const EVENT_TOUCHEND = `touchend${EVENT_KEY}`;
+ const EVENT_POINTERDOWN = `pointerdown${EVENT_KEY}`;
+ const EVENT_POINTERUP = `pointerup${EVENT_KEY}`;
+ const POINTER_TYPE_TOUCH = 'touch';
+ const POINTER_TYPE_PEN = 'pen';
+ const CLASS_NAME_POINTER_EVENT = 'pointer-event';
+ const SWIPE_THRESHOLD = 40;
+ const Default = {
+ endCallback: null,
+ leftCallback: null,
+ rightCallback: null
+ };
+ const DefaultType = {
+ endCallback: '(function|null)',
+ leftCallback: '(function|null)',
+ rightCallback: '(function|null)'
+ };
+
+ /**
+ * Class definition
+ */
+
+ class Swipe extends Config {
+ constructor(element, config) {
+ super();
+ this._element = element;
+ if (!element || !Swipe.isSupported()) {
+ return;
+ }
+ this._config = this._getConfig(config);
+ this._deltaX = 0;
+ this._supportPointerEvents = Boolean(window.PointerEvent);
+ this._initEvents();
+ }
+
+ // Getters
+ static get Default() {
+ return Default;
+ }
+ static get DefaultType() {
+ return DefaultType;
+ }
+ static get NAME() {
+ return NAME;
+ }
+
+ // Public
+ dispose() {
+ EventHandler.off(this._element, EVENT_KEY);
+ }
+
+ // Private
+ _start(event) {
+ if (!this._supportPointerEvents) {
+ this._deltaX = event.touches[0].clientX;
+ return;
+ }
+ if (this._eventIsPointerPenTouch(event)) {
+ this._deltaX = event.clientX;
+ }
+ }
+ _end(event) {
+ if (this._eventIsPointerPenTouch(event)) {
+ this._deltaX = event.clientX - this._deltaX;
+ }
+ this._handleSwipe();
+ index_js.execute(this._config.endCallback);
+ }
+ _move(event) {
+ this._deltaX = event.touches && event.touches.length > 1 ? 0 : event.touches[0].clientX - this._deltaX;
+ }
+ _handleSwipe() {
+ const absDeltaX = Math.abs(this._deltaX);
+ if (absDeltaX <= SWIPE_THRESHOLD) {
+ return;
+ }
+ const direction = absDeltaX / this._deltaX;
+ this._deltaX = 0;
+ if (!direction) {
+ return;
+ }
+ index_js.execute(direction > 0 ? this._config.rightCallback : this._config.leftCallback);
+ }
+ _initEvents() {
+ if (this._supportPointerEvents) {
+ EventHandler.on(this._element, EVENT_POINTERDOWN, event => this._start(event));
+ EventHandler.on(this._element, EVENT_POINTERUP, event => this._end(event));
+ this._element.classList.add(CLASS_NAME_POINTER_EVENT);
+ } else {
+ EventHandler.on(this._element, EVENT_TOUCHSTART, event => this._start(event));
+ EventHandler.on(this._element, EVENT_TOUCHMOVE, event => this._move(event));
+ EventHandler.on(this._element, EVENT_TOUCHEND, event => this._end(event));
+ }
+ }
+ _eventIsPointerPenTouch(event) {
+ return this._supportPointerEvents && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH);
+ }
+
+ // Static
+ static isSupported() {
+ return 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0;
+ }
+ }
+
+ return Swipe;
+
+}));
+//# sourceMappingURL=swipe.js.map