Skip to content

Commit

Permalink
Merge pull request #209 from marp-team/passive-listener
Browse files Browse the repository at this point in the history
Use passive event listener as much as possible
  • Loading branch information
yhatt authored Feb 25, 2020
2 parents 0ebcd44 + 2d488b4 commit d8ecb72
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 13 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@

- Use PptxGenJS v3 instead of `@marp-team/pptx` ([#205](https://github.com/marp-team/marp-cli/pull/205))
- Disable opening presenter view in `bespoke` template if using `localStorage` has restricted in browser ([#208](https://github.com/marp-team/marp-cli/pull/208))
- Use passive event listener as much as possible ([#209](https://github.com/marp-team/marp-cli/pull/209))

## v0.17.1 - 2020-02-22

Expand Down
35 changes: 22 additions & 13 deletions src/templates/bespoke/touch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,14 @@ export default function bespokeTouch(opts: BespokeTouchOption = {}) {
}
}

parent.addEventListener('touchstart', e => {
touchStart = e.touches.length === 1 ? touchPoint(e.touches[0]) : undefined
})
parent.addEventListener(
'touchstart',
e => {
touchStart =
e.touches.length === 1 ? touchPoint(e.touches[0]) : undefined
},
{ passive: true }
)

parent.addEventListener('touchmove', e => {
if (touchStart) {
Expand All @@ -51,17 +56,21 @@ export default function bespokeTouch(opts: BespokeTouchOption = {}) {
}
})

parent.addEventListener('touchend', e => {
if (touchStart) {
if (touchStart.delta && touchStart.delta >= options.swipeThreshold!) {
let radian = touchStart.radian! - options.slope!
radian = ((radian + Math.PI) % (Math.PI * 2)) - Math.PI
parent.addEventListener(
'touchend',
e => {
if (touchStart) {
if (touchStart.delta && touchStart.delta >= options.swipeThreshold!) {
let radian = touchStart.radian! - options.slope!
radian = ((radian + Math.PI) % (Math.PI * 2)) - Math.PI

deck[radian < 0 ? 'next' : 'prev']()
e.stopPropagation()
deck[radian < 0 ? 'next' : 'prev']()
e.stopPropagation()
}
touchStart = undefined
}
touchStart = undefined
}
})
},
{ passive: true }
)
}
}

0 comments on commit d8ecb72

Please sign in to comment.