Skip to content

Commit

Permalink
carousel: move common checks to a function
Browse files Browse the repository at this point in the history
  • Loading branch information
XhmikosR authored and GeoSot committed Jul 29, 2021
1 parent 742269a commit 04c4c50
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions js/src/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,13 @@ class Carousel extends BaseComponent {
}

_addTouchEventListeners() {
const hasPointerPenTouch = event => {
return this._pointerEvent &&
(event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)
}

const start = event => {
if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
if (hasPointerPenTouch(event)) {
this.touchStartX = event.clientX
} else if (!this._pointerEvent) {
this.touchStartX = event.touches[0].clientX
Expand All @@ -276,7 +281,7 @@ class Carousel extends BaseComponent {
}

const end = event => {
if (this._pointerEvent && (event.pointerType === POINTER_TYPE_PEN || event.pointerType === POINTER_TYPE_TOUCH)) {
if (hasPointerPenTouch(event)) {
this.touchDeltaX = event.clientX - this.touchStartX
}

Expand Down

0 comments on commit 04c4c50

Please sign in to comment.