clickoutside.js
975 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
'use strict';
Object.defineProperty(exports, "__esModule", {
value: true
});
exports.default = {
bind: function bind(el, binding, vNode) {
if (typeof binding.value !== 'function') {
var msg = 'in [clickoutside] directives, provided expression \'' + binding.expression + '\' is not a function ';
var compName = vNode.context.name;
if (compName) {
msg += 'in ' + compName;
}
console.error(msg);
}
var handler = function handler(e) {
if (!el.contains(e.target) && el !== e.target) {
binding.value(e);
} else {
return false;
}
};
el.__clickOutSide__ = handler;
document.addEventListener('click', handler, true);
},
unbind: function unbind(el) {
document.removeEventListener('click', el.__clickOutSide__, true);
el.__clickOutSide__ = null;
}
};