mirror of
https://github.com/danbulant/Nertivia-Client
synced 2026-06-14 20:11:10 +00:00
18 lines
No EOL
687 B
JavaScript
18 lines
No EOL
687 B
JavaScript
import Vue from 'vue'
|
|
|
|
// to close popout menus when clicking outside.
|
|
Vue.directive('click-outside', {
|
|
bind: function (el, binding, vnode) {
|
|
el.clickOutsideEvent = function (event) {
|
|
// here I check that click was outside the el and his childrens
|
|
if (!(el == event.target || el.contains(event.target))) {
|
|
// and if it did, call method provided in attribute value
|
|
vnode.context[binding.expression](event);
|
|
}
|
|
};
|
|
document.body.addEventListener('click', el.clickOutsideEvent)
|
|
},
|
|
unbind: function (el) {
|
|
document.body.removeEventListener('click', el.clickOutsideEvent)
|
|
},
|
|
}); |