fix for jenk autoscroll on page change

This commit is contained in:
2023-04-24 14:15:20 -05:00
parent 024c962567
commit 06d3642d08

View File

@@ -2,8 +2,8 @@ window.onload = function () {
onLoaded(); onLoaded();
}; };
function onLoaded() { function onLoaded() {
document.body.scrollTop = 0; // For Safari // document.body.scrollTop = 0; // For Safari
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera // document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
window.onresize = function () { window.onresize = function () {
resizer(); resizer();
@@ -88,6 +88,9 @@ async function goto(location, {push=true, toggle=true}={}) {
mode: "cors", mode: "cors",
}); });
const response = await a.json(); const response = await a.json();
if (!location.includes("#")) {
window.scrollTo({top: 0, left: 0, behavior:"instant"});
}
const metadata = response[0]; const metadata = response[0];
const content = response[1]; const content = response[1];
let root = document.getElementById("root"); let root = document.getElementById("root");
@@ -95,13 +98,12 @@ async function goto(location, {push=true, toggle=true}={}) {
root.querySelectorAll("script").forEach((x) => { root.querySelectorAll("script").forEach((x) => {
eval(x.innerHTML); eval(x.innerHTML);
}); });
document.querySelector("title").textContent = metadata['title'];
window.scrollTo(0, 0);
if (toggle) { if (toggle) {
toggleMenu(); toggleMenu();
} }
document.querySelector("title").textContent = metadata["title"];
if (push) { if (push) {
history.pushState(null, null, metadata['canonical']); history.pushState(null, null, metadata["canonical"]);
} }
} }