don't reload the page when navigating to an anchor

This commit is contained in:
Ell 2023-10-17 18:17:49 +02:00
parent eac391b364
commit f2d8da4e67

View file

@ -69,7 +69,12 @@
} }
let main = $("#main"); let main = $("#main");
$(window).on("hashchange", display); $(window).on("hashchange", e => {
let oldUrl = e.originalEvent?.oldURL;
let oldHash = oldUrl?.lastIndexOf("#");
if (oldHash && getId(oldUrl.substring(oldHash)) !== getId())
display();
});
display(); display();
function display() { function display() {
@ -92,8 +97,8 @@
}); });
} }
function getId() { function getId(hash) {
let hash = window.location.hash; hash ||= window.location.hash;
if (!hash) if (!hash)
return undefined; return undefined;
// hashes consist of the file id, a dash and then the permalink anchor name // hashes consist of the file id, a dash and then the permalink anchor name