2019-07-21 23:13:05 +08:00
|
|
|
import clickoutsideDelegate from '../utils/clickoutsideDelegate'
|
|
|
|
|
|
|
|
const ctx = '@@clickoutsideContext'
|
|
|
|
|
2019-07-22 15:15:55 +08:00
|
|
|
const clickoutside = {
|
2019-07-21 23:13:05 +08:00
|
|
|
inserted (el, bindings) {
|
2019-07-22 15:15:55 +08:00
|
|
|
console.log('[clickoutside]: inserted')
|
2019-07-21 23:13:05 +08:00
|
|
|
if (typeof bindings.value === 'function') {
|
|
|
|
el[ctx] = {
|
|
|
|
handler: bindings.value
|
|
|
|
}
|
2019-07-22 15:15:55 +08:00
|
|
|
clickoutsideDelegate.registerHandler(el, el[ctx].handler, false)
|
2019-07-21 23:13:05 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
update (el, bindings) {
|
|
|
|
if (typeof bindings.value === 'function') {
|
|
|
|
clickoutsideDelegate.unregisterHandler(el, el[ctx].handler)
|
|
|
|
el[ctx].handler = bindings.value
|
2019-07-22 15:15:55 +08:00
|
|
|
clickoutsideDelegate.registerHandler(el, el[ctx].handler, false)
|
2019-07-21 23:13:05 +08:00
|
|
|
}
|
|
|
|
},
|
|
|
|
unbind (el) {
|
2019-07-22 15:15:55 +08:00
|
|
|
console.log('[clickoutside]: unbind')
|
|
|
|
clickoutsideDelegate.unregisterHandler(el[ctx].handler)
|
2019-07-21 23:13:05 +08:00
|
|
|
}
|
|
|
|
}
|
2019-07-22 15:15:55 +08:00
|
|
|
|
|
|
|
export default clickoutside
|