SHARE
TWEET

Untitled

a guest Sep 22nd, 2019 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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>
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top