Advertisement
Guest User

Untitled

a guest
Sep 22nd, 2019
125
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.54 KB | None | 0 0
  1. import Vue from 'vue'
  2.  
  3. // initialize the directive
  4. export const a11yClick = {
  5. bind (el, binding) {
  6. let myFunction = binding.value
  7. el.addEventListener('click', myFunction)
  8. el.addEventListener('keypress', function (e) {
  9. let key = e.which || e.keyCode
  10. if (key === 13 || key === 32) { // 13 is enter, 32 is space bar
  11. e.preventDefault()
  12. binding.value()
  13. }
  14. })
  15. }
  16. }
  17.  
  18. // make it available globally
  19. Vue.directive('a11y-click', a11yClick)
  20.  
  21. // example usage:
  22. // <a v-a11y-click="myFunction" tabindex="0">view more</a>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement