Skip to content

Instantly share code, notes, and snippets.

@SaFrMo
Last active March 8, 2018 19:35
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save SaFrMo/5695faabbf523f0d88513c480cec891d to your computer and use it in GitHub Desktop.
Save SaFrMo/5695faabbf523f0d88513c480cec891d to your computer and use it in GitHub Desktop.
Common useful Vuepress functions
// catch newsletter button - any link with `#newsletter` triggers the callback
window.addEventListener('click', evt => {
if( evt.target && event.target.href && typeof evt.target.href == 'string' && event.target.href.indexOf('#newsletter') != -1 ){
evt.preventDefault()
// YOUR ACTION HERE...
}
})
// keys!
window.addEventListener('keydown', evt => {
if( evt.keyCode == 37 ){
// left arrow action
}
if( evt.keyCode == 38 ){
// up arrow action
}
if( evt.keyCode == 39 ){
// right arrow action
}
if( evt.keyCode == 40 ){
// down arrow action
}
})
// next/prev slides
nextSlide(){
this.index++
if( this.index >= this.slides.length ){
this.index = 0
}
},
prevSlide(){
this.index--
if( this.index < 0 ){
this.index = this.slides.length - 1
}
}
// blur a button somewhere in the chain
blurButton(evt, tag = 'BUTTON'){
if( evt && evt.path ){
const ancestorButton = evt.path.find(el => el.tagName == tag)
if( ancestorButton ){
ancestorButton.blur()
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment