mirror of
https://github.com/alrayyes/wiki.git
synced 2025-06-07 22:26:40 +00:00
chore: add window.addCleanup() for cleaning up handlers
This commit is contained in:
parent
8a6ebd1939
commit
c00089bd57
12 changed files with 47 additions and 49 deletions
quartz/components/scripts
|
@ -39,6 +39,9 @@ function notifyNav(url: FullSlug) {
|
|||
document.dispatchEvent(event)
|
||||
}
|
||||
|
||||
const cleanupFns: Set<(...args: any[]) => void> = new Set()
|
||||
window.addCleanup = (fn) => cleanupFns.add(fn)
|
||||
|
||||
let p: DOMParser
|
||||
async function navigate(url: URL, isBack: boolean = false) {
|
||||
p = p || new DOMParser()
|
||||
|
@ -57,6 +60,10 @@ async function navigate(url: URL, isBack: boolean = false) {
|
|||
|
||||
if (!contents) return
|
||||
|
||||
// cleanup old
|
||||
cleanupFns.forEach((fn) => fn())
|
||||
cleanupFns.clear()
|
||||
|
||||
const html = p.parseFromString(contents, "text/html")
|
||||
normalizeRelativeURLs(html, url)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue