diff options
author | tdro <tdro@noreply.example.com> | 2022-06-07 21:50:14 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2022-06-07 21:50:14 -0400 |
commit | f282dcf21b9024cc0c3a6f8b772aeb4ea8c4d3ec (patch) | |
tree | 6a13706783bb9b2348e02f9e3a4b212d2de1fe19 /static/js/pager.ts | |
parent | fd64030bb8378941b192f7c5c1701205652ee7e1 (diff) | |
download | canory-f282dcf21b9024cc0c3a6f8b772aeb4ea8c4d3ec.tar.gz canory-f282dcf21b9024cc0c3a6f8b772aeb4ea8c4d3ec.tar.bz2 canory-f282dcf21b9024cc0c3a6f8b772aeb4ea8c4d3ec.zip |
static/js/pager: Improve navigation loop
Final snap back for browsers that misalign on DOM content load. Remove
hash on scroll to allow implicit back to top navigation.
Diffstat (limited to 'static/js/pager.ts')
-rw-r--r-- | static/js/pager.ts | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/static/js/pager.ts b/static/js/pager.ts index f01de10..88e9f83 100644 --- a/static/js/pager.ts +++ b/static/js/pager.ts @@ -7,10 +7,13 @@ if (localStorage["settings"]) { settings = JSON.parse(localStorage["settings"]); } - if (self.location.href.indexOf("#") >= 0) { + if (self.location.hash.length > 0) { settings["pager"][url] = self.pageYOffset; localStorage["settings"] = JSON.stringify(settings); document.getElementById(location.hash.slice(1)).scrollIntoView(); + self.addEventListener("load", function () { + document.getElementById(location.hash.slice(1)).scrollIntoView(); + }); return; } if (settings["pager"][url] > 0) { @@ -25,6 +28,13 @@ const currentPosition = self.pageYOffset; settings["pager"][url] = currentPosition; localStorage["settings"] = JSON.stringify(settings); + if (self.location.hash.length === 0) { + history.replaceState( + {}, + document.title, + window.location.href.split("#")[0], + ); + } }); self.addEventListener("DOMContentLoaded", function () { |