mirror of
https://github.com/asimonson1125/asimonson1125.github.io.git
synced 2026-02-24 21:09:49 -06:00
fix for jenk autoscroll on page change
This commit is contained in:
@@ -2,8 +2,8 @@ window.onload = function () {
|
||||
onLoaded();
|
||||
};
|
||||
function onLoaded() {
|
||||
document.body.scrollTop = 0; // For Safari
|
||||
document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
||||
// document.body.scrollTop = 0; // For Safari
|
||||
// document.documentElement.scrollTop = 0; // For Chrome, Firefox, IE and Opera
|
||||
|
||||
window.onresize = function () {
|
||||
resizer();
|
||||
@@ -81,13 +81,16 @@ function toggleMenu() {
|
||||
}
|
||||
}
|
||||
|
||||
async function goto(location, {push=true, toggle=true}={}) {
|
||||
async function goto(location, { push = true, toggle = true } = {}) {
|
||||
let a = await fetch("/api/goto/" + location, {
|
||||
credentials: "include",
|
||||
method: "GET",
|
||||
mode: "cors",
|
||||
});
|
||||
const response = await a.json();
|
||||
if (!location.includes("#")) {
|
||||
window.scrollTo({top: 0, left: 0, behavior:"instant"});
|
||||
}
|
||||
const metadata = response[0];
|
||||
const content = response[1];
|
||||
let root = document.getElementById("root");
|
||||
@@ -95,17 +98,16 @@ async function goto(location, {push=true, toggle=true}={}) {
|
||||
root.querySelectorAll("script").forEach((x) => {
|
||||
eval(x.innerHTML);
|
||||
});
|
||||
document.querySelector("title").textContent = metadata['title'];
|
||||
window.scrollTo(0, 0);
|
||||
if(toggle){
|
||||
if (toggle) {
|
||||
toggleMenu();
|
||||
}
|
||||
if(push){
|
||||
history.pushState(null, null, metadata['canonical']);
|
||||
document.querySelector("title").textContent = metadata["title"];
|
||||
if (push) {
|
||||
history.pushState(null, null, metadata["canonical"]);
|
||||
}
|
||||
}
|
||||
|
||||
function backButton() {
|
||||
const location = window.location.pathname;
|
||||
goto(location.substring(1), {push:false}); // remove slash, goto already does that
|
||||
goto(location.substring(1), { push: false }); // remove slash, goto already does that
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user