mirror of
https://github.com/twbs/bootstrap.git
synced 2025-04-05 22:57:35 +02:00
Some checks failed
BrowserStack / browserstack (push) Has been cancelled
Bundlewatch / bundlewatch (push) Has been cancelled
CodeQL / Analyze (push) Has been cancelled
cspell / cspell (push) Has been cancelled
CSS / css (push) Has been cancelled
Docs / docs (push) Has been cancelled
JS Tests / JS Tests (push) Has been cancelled
Lint / lint (push) Has been cancelled
CSS (node-sass) / css (push) Has been cancelled
Release notes / update_release_draft (push) Has been cancelled
* Bump version to v5.3.4 * Dist * Dist * dist again * re-run npm release --------- Co-authored-by: Mark Otto <markdotto@gmail.com>
1 line
7.7 KiB
Plaintext
1 line
7.7 KiB
Plaintext
{"version":3,"file":"swipe.js","sources":["../../src/util/swipe.js"],"sourcesContent":["/**\n * --------------------------------------------------------------------------\n * Bootstrap util/swipe.js\n * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)\n * --------------------------------------------------------------------------\n */\n\nimport EventHandler from '../dom/event-handler.js'\nimport Config from './config.js'\nimport { execute } from './index.js'\n\n/**\n * Constants\n */\n\nconst NAME = 'swipe'\nconst EVENT_KEY = '.bs.swipe'\nconst EVENT_TOUCHSTART = `touchstart${EVENT_KEY}`\nconst EVENT_TOUCHMOVE = `touchmove${EVENT_KEY}`\nconst EVENT_TOUCHEND = `touchend${EVENT_KEY}`\nconst EVENT_POINTERDOWN = `pointerdown${EVENT_KEY}`\nconst EVENT_POINTERUP = `pointerup${EVENT_KEY}`\nconst POINTER_TYPE_TOUCH = 'touch'\nconst POINTER_TYPE_PEN = 'pen'\nconst CLASS_NAME_POINTER_EVENT = 'pointer-event'\nconst SWIPE_THRESHOLD = 40\n\nconst Default = {\n endCallback: null,\n leftCallback: null,\n rightCallback: null\n}\n\nconst DefaultType = {\n endCallback: '(function|null)',\n leftCallback: '(function|null)',\n rightCallback: '(function|null)'\n}\n\n/**\n * Class definition\n */\n\nclass Swipe extends Config {\n constructor(element, config) {\n super()\n this._element = element\n\n if (!element || !Swipe.isSupported()) {\n return\n }\n\n this._config = this._getConfig(config)\n this._deltaX = 0\n this._supportPointerEvents = Boolean(window.PointerEvent)\n this._initEvents()\n }\n\n // Getters\n static get Default() {\n return Default\n }\n\n static get DefaultType() {\n return DefaultType\n }\n\n static get NAME() {\n return NAME\n }\n\n // Public\n dispose() {\n EventHandler.off(this._element, EVENT_KEY)\n }\n\n // Private\n _start(event) {\n if (!this._supportPointerEvents) {\n this._deltaX = event.touches[0].clientX\n\n return\n }\n\n if (this._eventIsPointerPenTouch(event)) {\n this._deltaX = event.clientX\n }\n }\n\n _end(event) {\n if (this._eventIsPointerPenTouch(event)) {\n this._deltaX = event.clientX - this._deltaX\n }\n\n this._handleSwipe()\n execute(this._config.endCallback)\n }\n\n _move(event) {\n this._deltaX = event.touches && event.touches.length > 1 ?\n 0 :\n event.touches[0].clientX - this._deltaX\n }\n\n _handleSwipe() {\n const absDeltaX = Math.abs(this._deltaX)\n\n if (absDeltaX <= SWIPE_THRESHOLD) {\n return\n }\n\n const direction = absDeltaX / this._deltaX\n\n this._deltaX = 0\n\n if (!direction) {\n return\n }\n\n execute(direction > 0 ? this._config.rightCallback : this._config.leftCallback)\n }\n\n _initEvents() {\n if (this._supportPointerEvents) {\n EventHandler.on(this._element, EVENT_POINTERDOWN, event => this._start(event))\n EventHandler.on(this._element, EVENT_POINTERUP, event => this._end(event))\n\n this._element.classList.add(CLASS_NAME_POINTER_EVENT)\n } else {\n EventHandler.on(this._element, EVENT_TOUCHSTART, event => this._start(event))\n EventHandler.on(this._element, EVENT_TOUCHMOVE, event => this._move(event))\n EventHandler.on(this._element, EVENT_TOUCHEND, event => this._end(event))\n }\n }\n\n _eventIsPointerPenTouch(event) {\n return this._supportPointerEvents && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)\n }\n\n // Static\n static isSupported() {\n return 'ontouchstart' in document.documentElement || navigator.maxTouchPoints > 0\n }\n}\n\nexport default Swipe\n"],"names":["NAME","EVENT_KEY","EVENT_TOUCHSTART","EVENT_TOUCHMOVE","EVENT_TOUCHEND","EVENT_POINTERDOWN","EVENT_POINTERUP","POINTER_TYPE_TOUCH","POINTER_TYPE_PEN","CLASS_NAME_POINTER_EVENT","SWIPE_THRESHOLD","Default","endCallback","leftCallback","rightCallback","DefaultType","Swipe","Config","constructor","element","config","_element","isSupported","_config","_getConfig","_deltaX","_supportPointerEvents","Boolean","window","PointerEvent","_initEvents","dispose","EventHandler","off","_start","event","touches","clientX","_eventIsPointerPenTouch","_end","_handleSwipe","execute","_move","length","absDeltaX","Math","abs","direction","on","classList","add","pointerType","document","documentElement","navigator","maxTouchPoints"],"mappings":";;;;;;;;;;;EAAA;EACA;EACA;EACA;EACA;EACA;;;EAMA;EACA;EACA;;EAEA,MAAMA,IAAI,GAAG,OAAO;EACpB,MAAMC,SAAS,GAAG,WAAW;EAC7B,MAAMC,gBAAgB,GAAG,CAAaD,UAAAA,EAAAA,SAAS,CAAE,CAAA;EACjD,MAAME,eAAe,GAAG,CAAYF,SAAAA,EAAAA,SAAS,CAAE,CAAA;EAC/C,MAAMG,cAAc,GAAG,CAAWH,QAAAA,EAAAA,SAAS,CAAE,CAAA;EAC7C,MAAMI,iBAAiB,GAAG,CAAcJ,WAAAA,EAAAA,SAAS,CAAE,CAAA;EACnD,MAAMK,eAAe,GAAG,CAAYL,SAAAA,EAAAA,SAAS,CAAE,CAAA;EAC/C,MAAMM,kBAAkB,GAAG,OAAO;EAClC,MAAMC,gBAAgB,GAAG,KAAK;EAC9B,MAAMC,wBAAwB,GAAG,eAAe;EAChD,MAAMC,eAAe,GAAG,EAAE;EAE1B,MAAMC,OAAO,GAAG;EACdC,EAAAA,WAAW,EAAE,IAAI;EACjBC,EAAAA,YAAY,EAAE,IAAI;EAClBC,EAAAA,aAAa,EAAE;EACjB,CAAC;EAED,MAAMC,WAAW,GAAG;EAClBH,EAAAA,WAAW,EAAE,iBAAiB;EAC9BC,EAAAA,YAAY,EAAE,iBAAiB;EAC/BC,EA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