mirror of
https://github.com/squidfunk/mkdocs-material.git
synced 2024-06-14 11:52:32 +03:00
Improved anchor jumps after instant loading and fixed Google Analytics
This commit is contained in:
parent
ab3ef19498
commit
067df2f6cf
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
1
material/assets/javascripts/bundle.b70c6ac3.min.js.map
Normal file
1
material/assets/javascripts/bundle.b70c6ac3.min.js.map
Normal file
File diff suppressed because one or more lines are too long
@ -1,6 +1,6 @@
|
||||
{
|
||||
"assets/javascripts/bundle.js": "assets/javascripts/bundle.4de2b008.min.js",
|
||||
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.4de2b008.min.js.map",
|
||||
"assets/javascripts/bundle.js": "assets/javascripts/bundle.b70c6ac3.min.js",
|
||||
"assets/javascripts/bundle.js.map": "assets/javascripts/bundle.b70c6ac3.min.js.map",
|
||||
"assets/javascripts/worker/search.js": "assets/javascripts/worker/search.926ffd9e.min.js",
|
||||
"assets/javascripts/worker/search.js.map": "assets/javascripts/worker/search.926ffd9e.min.js.map",
|
||||
"assets/stylesheets/main.css": "assets/stylesheets/main.1e07d700.min.css",
|
||||
|
@ -195,7 +195,7 @@
|
||||
{% endblock %}
|
||||
</div>
|
||||
{% block scripts %}
|
||||
<script src="{{ 'assets/javascripts/bundle.4de2b008.min.js' | url }}"></script>
|
||||
<script src="{{ 'assets/javascripts/bundle.b70c6ac3.min.js' | url }}"></script>
|
||||
{%- set translations = {} -%}
|
||||
{%- for key in [
|
||||
"clipboard.copy",
|
||||
|
@ -2,5 +2,5 @@
|
||||
This file was automatically generated - do not edit
|
||||
-#}
|
||||
{% set analytics = config.google_analytics %}
|
||||
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","{{ analytics[0] }}","{{ analytics[1] }}"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})})</script>
|
||||
<script>window.ga=window.ga||function(){(ga.q=ga.q||[]).push(arguments)},ga.l=+new Date,ga("create","{{ analytics[0] }}","{{ analytics[1] }}"),ga("set","anonymizeIp",!0),ga("send","pageview"),document.addEventListener("DOMContentLoaded",function(){document.forms.search&&document.forms.search.query.addEventListener("blur",function(){if(this.value){var e=document.location.pathname;ga("send","pageview",e+"?q="+this.value)}})}),document.addEventListener("DOMContentSwitch",function(){ga("send","pageview")})</script>
|
||||
<script async src="https://www.google-analytics.com/analytics.js"></script>
|
||||
|
@ -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)
|
||||
}
|
||||
}
|
||||
|
@ -45,5 +45,10 @@
|
||||
})
|
||||
}
|
||||
})
|
||||
|
||||
/* Send page view on document switch (instant loading, custom event) */
|
||||
document.addEventListener("DOMContentSwitch", function() {
|
||||
ga("send", "pageview")
|
||||
})
|
||||
</script>
|
||||
<script async src="https://www.google-analytics.com/analytics.js"></script>
|
||||
|
Loading…
Reference in New Issue
Block a user