cartodb-4.42/lib/assets/javascripts/new-dashboard/directives/click-outside.js

22 lines
714 B
JavaScript
Raw Normal View History

2024-04-06 13:25:13 +08:00
import Vue from 'vue';
Vue.directive('clickOutside', {
bind: function (element, binding, vnode) {
element.clickOutsideEvent = function (event) {
if (!element.contains(event.target)) {
vnode.context[binding.expression](event);
}
};
element.addClickEvent = function (event) {
document.body.addEventListener('click', element.clickOutsideEvent, { passive: true });
};
element.addEventListener('click', element.addClickEvent, { passive: true });
},
unbind: function (element) {
document.body.removeEventListener('click', element.clickOutsideEvent, { passive: true });
element.removeEventListener('click', element.addClickEvent, { passive: true });
}
});