Improved anchor jumps after instant loading and fixed Google Analytics

This commit is contained in:
squidfunk
2020-02-29 20:57:11 +01:00
parent ab3ef19498
commit 067df2f6cf
9 changed files with 31 additions and 30 deletions

View File

@@ -462,6 +462,9 @@ export function initialize(config: unknown) {
.subscribe(([{ url, data }, { title, head }]) => {
console.log("Done", url.href, data)
// trigger custom event
document.dispatchEvent(new CustomEvent("DOMContentSwitch"))
// setDocumentTitle
document.title = title
@@ -481,21 +484,20 @@ export function initialize(config: unknown) {
}
}
// // TODO: this doesnt work as expected
// if (!data) {
// const { hash } = new URL(href)
// if (hash) {
// const el = getElement(hash)
// if (typeof el !== "undefined") {
// el.scrollIntoView()
// return
// }
// }
// }
// search drawer close
useToggle("search").subscribe(el => {
setToggle(el, false)
})
// console.log(ev)
// if (!data)
setViewportOffset(data || { y: 0 }) // push state!
// // TODO: this doesnt work as expected
if (url.hash) {
console.log("hash data?", data)
const a = document.createElement("a")
a.href = url.hash
a.click()
} else {
setViewportOffset(data || { y: 0 }) // push state!
}
})
// internal$.subscribe(({ url }) => {

View File

@@ -74,16 +74,10 @@ export function patchScripts(
/* Evaluate all scripts via replacement */
els$.subscribe(els => {
for (const el of els) {
if (
el.src || !el.type ||
/^(application|text)\/javascript$/i.test(el.type)
) {
if (el.src || /(^|\/javascript)$/i.test(el.type)) {
const script = document.createElement("script")
if (el.src) {
script.src = el.src
} else {
script.innerText = el.innerText
}
const key = el.src ? "src" : "innerText"
script[key] = el[key]
el.replaceWith(script)
}
}