feat(derictive): add clickoutside derictive

This commit is contained in:
07akioni 2019-07-21 23:13:05 +08:00
parent af62756c74
commit 7be130ff9b
2 changed files with 31 additions and 0 deletions

View File

@ -30,6 +30,13 @@ function dateItem (time, displayTime, selectedTime, currentTime) {
}
}
/**
* Given time to display calendar, given the selected time, given current time,
* return the date array of display time's month.
* @param {Moment} displayTime
* @param {Moment} selectedTime
* @param {Moment} currentTime
*/
function dateArray (displayTime, selectedTime, currentTime) {
const displayMonth = displayTime.month()
/**

View File

@ -0,0 +1,24 @@
import clickoutsideDelegate from '../utils/clickoutsideDelegate'
const ctx = '@@clickoutsideContext'
export const clickoutside = {
inserted (el, bindings) {
if (typeof bindings.value === 'function') {
el[ctx] = {
handler: bindings.value
}
clickoutsideDelegate.registerHandler(el, el[ctx].handler)
}
},
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)
}
},
unbind (el) {
clickoutsideDelegate.unregisterHandler(el, el[ctx].handler)
}
}