Last active
March 8, 2018 19:35
-
-
Save SaFrMo/5695faabbf523f0d88513c480cec891d to your computer and use it in GitHub Desktop.
Common useful Vuepress functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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