basic search implementation
This commit is contained in:
parent
c4cf0dcb02
commit
fd5c8d17d3
26 changed files with 751 additions and 182 deletions
19
quartz/components/scripts/handler.ts
Normal file
19
quartz/components/scripts/handler.ts
Normal file
|
@ -0,0 +1,19 @@
|
|||
export function registerEscapeHandler(outsideContainer: HTMLElement | null, cb: () => void) {
|
||||
if (!outsideContainer) return
|
||||
function click(this: HTMLElement, e: HTMLElementEventMap["click"]) {
|
||||
if (e.target !== this) return
|
||||
e.preventDefault()
|
||||
cb()
|
||||
}
|
||||
|
||||
function esc(e: HTMLElementEventMap["keydown"]) {
|
||||
if (!e.key.startsWith("Esc")) return
|
||||
e.preventDefault()
|
||||
cb()
|
||||
}
|
||||
|
||||
outsideContainer?.removeEventListener("click", click)
|
||||
outsideContainer?.addEventListener("click", click)
|
||||
document.removeEventListener("keydown", esc)
|
||||
document.addEventListener('keydown', esc)
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue