mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2026-07-23 06:13:38 -04:00
Improved anchor jumps after instant loading and fixed Google Analytics
This commit is contained in:
@@ -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 }) => {
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user