mirror of
https://github.com/koel/koel
synced 2024-12-20 09:33:23 +00:00
15 lines
478 B
TypeScript
15 lines
478 B
TypeScript
import { Directive } from 'vue'
|
|
|
|
let handler: any
|
|
|
|
/**
|
|
* A fork of https://github.com/simplesmiler/vue-clickaway.
|
|
* Trigger a function if the user clicks out of the bound element.
|
|
*/
|
|
export const clickaway: Directive = {
|
|
mounted (el: HTMLElement, { value }: { value: TAnyFunction }): void {
|
|
handler = (e: MouseEvent) => el.contains(e.target as Node) || value()
|
|
document.addEventListener('click', handler)
|
|
document.addEventListener('contextmenu', handler)
|
|
}
|
|
}
|