Permalink
Browse files

Enhance back button for each post to redirect to the last known page

  • Loading branch information...
1 parent 408b6e2 commit 6c75375b6a08310ddb1b909db039ea62faa30f1f @kelyvin committed May 2, 2016
Oops, something went wrong.
Oops, something went wrong.
@@ -34,6 +34,17 @@ $(function() {
}
},
+ redirect: function (pageNum) {
+ var redirectUrl = "";
+
+ if (pageNum > 1) {
+ redirectUrl += "/page/" + pageNum + "/#open";
+ } else {
+ redirectUrl += "/#open";
+ }
+
+ window.location.href = redirectUrl;
+ },
isOpen: function () {
return location.hash === openHash;
},
@@ -46,6 +57,18 @@ $(function() {
close: function() {
window.history.replaceState(null, null, "#");
},
+ getLastPageNum: function() {
+ var pageNum = window.store.get("pageNum") || "";
+
+ return pageNum;
+ },
+ setLastPageNum: function() {
+ var pageNum = $("#pageNum").text() || "";
+
+ if (pageNum.length > 0) {
+ window.store.set("pageNum", pageNum);
+ }
+ },
readTime: function() {
var DateInDays;
DateInDays = function(selector) {
View
@@ -45,17 +45,30 @@ $(function() {
$(".subscribe-button").removeClass("hide");
}
+ // "Home" page setup
if (CaffeineTheme.is("page", "home")) {
if (!CaffeineTheme.isOpen()) {
CaffeineTheme.hideIndexPage();
}
}
+ // "Post" page setup
if (CaffeineTheme.is("page", "post")) {
$("main").readingTime({
readingTimeTarget: ".reading-time > span"
});
$(".content").fitVids();
+
+ $("#back-button").on("click", function (event) {
+ var lastPageNum = CaffeineTheme.getLastPageNum();
+ event.preventDefault();
+
+ if (lastPageNum.length > 0) {
+ CaffeineTheme.redirect(lastPageNum);
+ } else {
+ window.history.back();
+ }
+ });
}
// Sets up masonry effects
@@ -79,7 +92,7 @@ $(function() {
}
// Check if local store is enabled. This is required.
- if (!store.enabled) {
+ if (!window.store.enabled) {
return;
}
@@ -106,5 +119,7 @@ $(function() {
} else {
$posts.css("visibility", "visible");
}
+
+ CaffeineTheme.setLastPageNum();
});
});
@@ -37,5 +37,6 @@
margin-left: 16px;
font-size: 12px;
color: $gray-dark;
+ display: inline;
}
}
@@ -2,7 +2,7 @@
{{#if prev}}
<a rel="next" class="newer btn small hvr-grow" href="{{page_url prev}}#open"><i class="fa fa-arrow-left"></i> Newer Posts</a>
{{/if}}
- <span class="index">Page {{page}} of {{pages}}</span>
+ <div class="index">Page <span id="pageNum">{{page}}</span> of {{pages}}</div>
{{#if next}}
<a rel="prev" class="older btn small hvr-grow" href="{{page_url next}}#open">Older Posts <i class="fa fa-arrow-right"></i></a>
{{/if}}
View
@@ -5,7 +5,7 @@
<article class="{{post_class}}">
{{> material-cover}}
<div class="post-card animated fade-in">
- <a href="javascript:window.history.back()" title="Go back" class="hvr-grow">
+ <a id="back-button" href="#open" title="Go back" class="hvr-grow">
<div class="back-button">
<i class="fa fa-arrow-left"></i>
</div>

0 comments on commit 6c75375

Please sign in to comment.