Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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