2016-06-25 16:05:24 +00:00
|
|
|
/**
|
|
|
|
* A fork of https://github.com/simplesmiler/vue-clickaway.
|
|
|
|
* Trigger a function if the user clicks out of the bound element.
|
|
|
|
* @type {Object}
|
|
|
|
*/
|
|
|
|
export const clickawayDirective = {
|
2016-11-26 03:25:35 +00:00
|
|
|
bind (el, { value }) {
|
2016-06-25 16:05:24 +00:00
|
|
|
if (typeof value !== 'function') {
|
2016-11-26 03:25:35 +00:00
|
|
|
console.warn(`Expect a function, got ${value}`)
|
|
|
|
return
|
2016-06-25 16:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
document.addEventListener('click', e => {
|
2017-01-17 07:02:19 +00:00
|
|
|
el.contains(e.target) || value()
|
2016-11-26 03:25:35 +00:00
|
|
|
})
|
|
|
|
}
|
2016-06-25 16:05:24 +00:00
|
|
|
}
|