improves custom v-closable directive
This commit is contained in:
@@ -15,7 +15,7 @@
|
||||
</a>
|
||||
</div>
|
||||
<div class="dropdown-menu" id="dropdown-menu" role="menu"
|
||||
v-closable="{ exclude: ['dropdown_btn'], handler: 'closeDropdown' }">
|
||||
v-closable="{ exclude: ['dropdown_btn'], handler: 'closeDropdown', visible: show_dropdown }">
|
||||
<div class="dropdown-content">
|
||||
<a v-for="(p,i) in player_list" :key="i"
|
||||
@click="setActivePlayer(i)"
|
||||
@@ -75,6 +75,7 @@
|
||||
],
|
||||
show_dropdown: false,
|
||||
edit_wealth: false,
|
||||
handleOutsideClick: null,
|
||||
};
|
||||
},
|
||||
computed: {
|
||||
@@ -109,7 +110,6 @@
|
||||
'closable': {
|
||||
bind: function(el, binding, vnode) {
|
||||
handleOutsideClick = (e) => {
|
||||
console.log("outsideClick");
|
||||
e.stopPropagation();
|
||||
const { exclude, handler } = binding.value;
|
||||
let excludedElClicked = false;
|
||||
@@ -125,12 +125,21 @@
|
||||
vnode.context[handler]()
|
||||
}
|
||||
};
|
||||
document.addEventListener('click', handleOutsideClick);
|
||||
document.addEventListener('touchstart', handleOutsideClick);
|
||||
},
|
||||
// Bind custom handler only when dropdown is visible
|
||||
update: function(el, binding, vnode, _) {
|
||||
const { visible } = binding.value;
|
||||
if (visible) {
|
||||
document.addEventListener('click', handleOutsideClick);
|
||||
document.addEventListener('touchstart', handleOutsideClick);
|
||||
} else {
|
||||
document.removeEventListener('click', handleOutsideClick);
|
||||
document.removeEventListener('touchstart', handleOutsideClick);
|
||||
}
|
||||
},
|
||||
unbind: function() { console.log("unbind");
|
||||
document.removeEventListener('click', handleOustideClick);
|
||||
document.removeEventListener('touchstart', handleOustideClick);
|
||||
document.removeEventListener('click', handleOutsideClick);
|
||||
document.removeEventListener('touchstart', handleOutsideClick);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user