From d656d483a3925385e419b5664c7b25b8c9204510 Mon Sep 17 00:00:00 2001 From: notcarbide <41094677+notcarbide@users.noreply.github.com> Date: Thu, 15 Oct 2020 18:32:50 -0400 Subject: static: js: main: Add check for hash Without this, visiting an article and pressing the 'close' icon will go back, instead of closing the article. Also use replaceState to mimic behavior of pressing back, otherwise, a random hash will be added when closing from visiting an article first. --- static/assets/js/main.js | 28 ++++++++++++++++++++++------ 1 file changed, 22 insertions(+), 6 deletions(-) diff --git a/static/assets/js/main.js b/static/assets/js/main.js index 8cd9fa7..5c00084 100644 --- a/static/assets/js/main.js +++ b/static/assets/js/main.js @@ -67,7 +67,12 @@ // Main. var delay = 325, - locked = false; + locked = false, + nohash = false; + + // Set nohash. + if (location.hash == '' || location.hash == '#') + nohash = true; // Methods. $main._show = function(id, initial) { @@ -208,7 +213,7 @@ // Add state? if (typeof addState != 'undefined' && addState === true) - history.pushState(null, null, '#'); + history.replaceState(null, null, '/'); // Handle lock. @@ -295,7 +300,12 @@ $('
Close
') .appendTo($this) .on('click', function() { - history.go(-1); + if (nohash) { + history.go(-1); + } else { + $main._hide(true); + nohash = true; + } }); // Prevent clicks from inside article from bubbling. @@ -308,9 +318,15 @@ // Events. $body.on('click', function(event) { - // Outside click. Article visible. Go Back. - if ($body.hasClass('is-article-visible')) - history.go(-1); + // Article visible? Go back. Hide when article is accessed first. + if ($body.hasClass('is-article-visible')) { + if (nohash) { + history.go(-1); + } else { + $main._hide(true); + nohash = true; + } + } }); -- cgit v1.2.3