Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use passive event listener as much as possible #209

Merged
merged 2 commits into from
Feb 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 }
)
}
}