bootstrap-vue
Version:
BootstrapVue provides one of the most comprehensive implementations of Bootstrap 4 components and grid system for Vue.js and with extensive and automated WAI-ARIA accessibility markup.
50 lines (40 loc) • 1.5 kB
JavaScript
import { keys } from '../utils/object';
var allListenTypes = { hover: true, click: true, focus: true };
var BVBoundListeners = '__BV_boundEventListeners__';
var bindTargets = function bindTargets(vnode, binding, listenTypes, fn) {
var targets = keys(binding.modifiers || {}).filter(function (t) {
return !allListenTypes[t];
});
if (binding.value) {
targets.push(binding.value);
}
var listener = function listener() {
fn({ targets: targets, vnode: vnode });
};
keys(allListenTypes).forEach(function (type) {
if (listenTypes[type] || binding.modifiers[type]) {
vnode.elm.addEventListener(type, listener);
var boundListeners = vnode.elm[BVBoundListeners] || {};
boundListeners[type] = boundListeners[type] || [];
boundListeners[type].push(listener);
vnode.elm[BVBoundListeners] = boundListeners;
}
});
// Return the list of targets
return targets;
};
var unbindTargets = function unbindTargets(vnode, binding, listenTypes) {
keys(allListenTypes).forEach(function (type) {
if (listenTypes[type] || binding.modifiers[type]) {
var boundListeners = vnode.elm[BVBoundListeners] && vnode.elm[BVBoundListeners][type];
if (boundListeners) {
boundListeners.forEach(function (listener) {
return vnode.elm.removeEventListener(type, listener);
});
delete vnode.elm[BVBoundListeners][type];
}
}
});
};
export { bindTargets, unbindTargets };
export default bindTargets;