mirror of
https://github.com/tusen-ai/naive-ui.git
synced 2024-12-27 05:00:48 +08:00
29 lines
800 B
JavaScript
29 lines
800 B
JavaScript
import clickoutsideDelegate from '../utils/clickoutsideDelegate'
|
|
|
|
const ctx = '@@clickoutsideContext'
|
|
|
|
const clickoutside = {
|
|
inserted (el, bindings) {
|
|
console.log('[clickoutside]: inserted')
|
|
if (typeof bindings.value === 'function') {
|
|
el[ctx] = {
|
|
handler: bindings.value
|
|
}
|
|
clickoutsideDelegate.registerHandler(el, el[ctx].handler, false)
|
|
}
|
|
},
|
|
update (el, bindings) {
|
|
if (typeof bindings.value === 'function') {
|
|
clickoutsideDelegate.unregisterHandler(el, el[ctx].handler)
|
|
el[ctx].handler = bindings.value
|
|
clickoutsideDelegate.registerHandler(el, el[ctx].handler, false)
|
|
}
|
|
},
|
|
unbind (el) {
|
|
console.log('[clickoutside]: unbind')
|
|
clickoutsideDelegate.unregisterHandler(el[ctx].handler)
|
|
}
|
|
}
|
|
|
|
export default clickoutside
|