diff options
author | notcarbide <41094677+notcarbide@users.noreply.github.com> | 2020-10-16 01:32:50 +0300 |
---|---|---|
committer | notcarbide <41094677+notcarbide@users.noreply.github.com> | 2020-10-16 01:36:26 +0300 |
commit | d656d483a3925385e419b5664c7b25b8c9204510 (patch) | |
tree | 6c6c6c837b7b76d148bb7f06c008863cec75de8b | |
parent | f9d2b5b481e8a287d7d5be9ecb9f7c787e00e6f8 (diff) |
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.
-rw-r--r-- | static/assets/js/main.js | 28 |
1 files 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 @@ $('<div class="close">Close</div>')
.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;
+ }
+ }
});
|