Spaces:
Paused
Paused
Download src/lib/actions/clickOutside.ts from vollsteksolutions/test: direct link, hf CLI and curl.
- Browser
- Download file 443 Bytes
-
https://huggingface.co/spaces/vollsteksolutions/test/resolve/main/src/lib/actions/clickOutside.ts
- Command line
-
hf download hf://spaces/vollsteksolutions/test/src/lib/actions/clickOutside.ts
-
curl -L -o clickOutside.ts https://huggingface.co/spaces/vollsteksolutions/test/resolve/main/src/lib/actions/clickOutside.ts
443 Bytes
| export function clickOutside(element: HTMLDialogElement, callbackFunction: () => void) { | |
| function onClick(event: MouseEvent) { | |
| if (!element.contains(event.target as Node)) { | |
| callbackFunction(); | |
| } | |
| } | |
| document.body.addEventListener("click", onClick); | |
| return { | |
| update(newCallbackFunction: () => void) { | |
| callbackFunction = newCallbackFunction; | |
| }, | |
| destroy() { | |
| document.body.removeEventListener("click", onClick); | |
| }, | |
| }; | |
| } | |