Skip to content

Commit

Permalink
fix: remove the side-effects by removing only our event listener
Browse files Browse the repository at this point in the history
  • Loading branch information
mmorainville committed Mar 13, 2018
1 parent d7e8d42 commit 3b9e389
Showing 1 changed file with 19 additions and 18 deletions.
37 changes: 19 additions & 18 deletions src/components/VTour.vue
Original file line number Diff line number Diff line change
Expand Up @@ -56,28 +56,13 @@ export default {
this.$tours[this.name] = this
if (this.customOptions.useKeyboardNavigation) {
window.addEventListener('keyup', e => {
// TODO: debug mode
// console.log('[Vue Tour] A keyup event occured:', e)
switch (e.keyCode) {
case KEYS.ARROW_RIGHT:
this.nextStep()
break
case KEYS.ARROW_LEFT:
this.previousStep()
break
case KEYS.ESCAPE:
this.stop()
break
}
})
window.addEventListener('keyup', this.handleKeyup)
}
},
beforeDestroy () {
// Remove the keyup listener if it has been defined.
// Might have side-effects if the user already defined a listener on keyup.
// Remove the keyup listener if it has been defined
if (this.customOptions.useKeyboardNavigation) {
window.removeEventListener('keyup')
window.removeEventListener('keyup', this.handleKeyup)
}
},
computed: {
Expand Down Expand Up @@ -118,6 +103,22 @@ export default {
},
stop () {
this.currentStep = -1
},
handleKeyup (e) {
// TODO: debug mode
// console.log('[Vue Tour] A keyup event occured:', e)
switch (e.keyCode) {
case KEYS.ARROW_RIGHT:
this.nextStep()
break
case KEYS.ARROW_LEFT:
this.previousStep()
break
case KEYS.ESCAPE:
this.stop()
break
}
}
}
}
Expand Down

0 comments on commit 3b9e389

Please sign in to comment.