diff options
author | tdro <tdro@noreply.example.com> | 2023-10-11 19:37:23 -0400 |
---|---|---|
committer | tdro <tdro@noreply.example.com> | 2023-10-11 19:37:23 -0400 |
commit | fa7693d5f9f6594e54953bb08a2184cb0b4647fd (patch) | |
tree | eef573754ca1d736a5e484e04f30225c00bc2812 /assets/js/index.js | |
parent | 5c07a9a50fa0f60939a2527d339230421448c6c6 (diff) | |
download | canory-fa7693d5f9f6594e54953bb08a2184cb0b4647fd.tar.gz canory-fa7693d5f9f6594e54953bb08a2184cb0b4647fd.tar.bz2 canory-fa7693d5f9f6594e54953bb08a2184cb0b4647fd.zip |
static/js/pager: Avoid async conflict between track and restore
Diffstat (limited to 'assets/js/index.js')
-rw-r--r-- | assets/js/index.js | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/assets/js/index.js b/assets/js/index.js index acdcd57..4ca5e4a 100644 --- a/assets/js/index.js +++ b/assets/js/index.js @@ -10,33 +10,33 @@ }; const key = "settings"; const url = self.location.href.split("#")[0].split("?")[0]; + if (!localStorage[key]) localStorage[key] = JSON.stringify(settings); const scrollRestore = function(url) { if (history.scrollRestoration) history.scrollRestoration = "manual"; - if (localStorage[key]) settings = JSON.parse(localStorage[key]); - const fragment = document.getElementById(location.hash.slice(1)); + settings = JSON.parse(localStorage[key]); + const fragment = self.location.hash.slice(1) && document.getElementById(self.location.hash.slice(1)); const fragmentInURL = self.location.hash.length > 0; if (fragmentInURL && document.body.contains(fragment)) { settings["pager"][url] = self.pageYOffset; localStorage[key] = JSON.stringify(settings); fragment.scrollIntoView(); - self.addEventListener("DOMContentLoaded", function() { + return self.addEventListener("DOMContentLoaded", function() { fragment.scrollIntoView(); }); - return; } if (settings["pager"][url] > 0) { - self.scrollTo(0, settings["pager"][url]); - return; + return self.scrollTo(0, settings["pager"][url]); } settings["pager"][url] = self.pageYOffset; localStorage[key] = JSON.stringify(settings); }; const scrollTrack = function(url) { const currentPosition = self.pageYOffset; + settings = JSON.parse(localStorage[key]); settings["pager"][url] = currentPosition; localStorage[key] = JSON.stringify(settings); }; - const backTrack = function(back, up, event) { + const reverseTrack = function(back, up, event) { if (document.body.contains(up) && up.contains(event.target)) { event.preventDefault(); window.scrollTo(0, 0); @@ -52,7 +52,7 @@ self.addEventListener("click", function(event) { const up = document.getElementById("top"); const back = document.getElementById("back"); - backTrack(back, up, event); + reverseTrack(back, up, event); }); }); self.addEventListener("hashchange", function() { @@ -63,7 +63,7 @@ "touchstart", "scroll" ].forEach(function(event) { - self.addEventListener(event, function(event) { + self.addEventListener(event, function() { scrollTrack(url); }); }); @@ -400,7 +400,7 @@ "keyup", "click" ].forEach(function(event) { - form.addEventListener(event, function(event) { + form.addEventListener(event, function() { if (document.activeElement.nodeName === "A") { return selected = document.activeElement; } |