All files / src/directives/v-click-outside index.js

18.18% Statements 2/11
0% Branches 0/6
0% Functions 0/4
18.18% Lines 2/11

Press n or j to go to the next uncovered block, b, p or k for the previous block.

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    7x                 7x                            
import single from '../../utils/event/single';
 
const handler = function (e, data) {
    Object.values(data).forEach(({ el, binding }) => {
        if (el.contains(e.target))
            return false;
        if (binding.expression)
            binding.value(e);
    });
};
 
export const clickOutside = {
    bind(el, binding) {
        el['v-click-outside-off'] = single.on('v-click-outside' + new Date(), {
            el,
            binding,
        }, document, 'click', handler);
    },
    unbind(el) {
        if (el['v-click-outside-off']) {
            el['v-click-outside-off']();
            delete el['v-click-outside-off'];
        }
    },
};