Created
April 13, 2019 20:28
-
-
Save rebz/08077eb88bf1aa1918e28b5228bc26c8 to your computer and use it in GitHub Desktop.
Custom directive to drop in a project for Modal-esque elements.
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
/* | |
* Add `v-click-outside="function"` to your element. | |
* Does not take into account 'touchstart' | |
*/ | |
export default { | |
bind: function (el, binding, vnode) { | |
el.event = function (event) { | |
if (!(el == event.target || el.contains(event.target))) { | |
vnode.context[binding.expression](event); | |
} | |
} | |
document.body.addEventListener('click', el.event) | |
}, | |
unbind: function (el) { | |
document.body.removeEventListener('click', el.event) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment