2021-03-31 11:59:07 +02:00
|
|
|
export default function clickOutside(element, callbackFunction) {
|
|
|
|
function onClick(event) {
|
|
|
|
if (!element.contains(event.target)) {
|
|
|
|
callbackFunction()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-04-20 13:20:03 +02:00
|
|
|
document.body.addEventListener("mousedown", onClick, true)
|
2021-03-31 11:59:07 +02:00
|
|
|
|
|
|
|
return {
|
|
|
|
update(newCallbackFunction) {
|
|
|
|
callbackFunction = newCallbackFunction
|
|
|
|
},
|
|
|
|
destroy() {
|
2021-04-20 13:20:03 +02:00
|
|
|
document.body.removeEventListener("mousedown", onClick, true)
|
2021-03-31 11:59:07 +02:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|