Skip to content

Commit

Permalink
Update: infinite scroll on index page and posts
Browse files Browse the repository at this point in the history
  • Loading branch information
qinwf committed Oct 18, 2016
1 parent b073945 commit 6a16c2b
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 7 deletions.
21 changes: 21 additions & 0 deletions _includes/inf.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@

<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>

<script src="https://cdnjs.cloudflare.com/ajax/libs/jscroll/2.3.5/jquery.jscroll.min.js"></script>

<script type="text/javascript">
// content selector is used to extract the additional items
var repat = new RegExp("https?://");
$('.content').jscroll({
contentSelector: '#posts-content',
nextSelector: '#next-page',
loadingFunction: function(){
var new_page = $('#next-page')[0].href.replace(/(https:\/\/)|(http:\/\/)/, '');
var xhr = new XMLHttpRequest();
xhr.open("GET","https://page.rweekly.org/?page="+ new_page);
xhr.send();
}
});
</script>
1 change: 1 addition & 0 deletions _layouts/default.html
Original file line number Diff line number Diff line change
Expand Up @@ -104,5 +104,6 @@ <h3 class="masthead-title">
})();

</script>

</body>
</html>
17 changes: 15 additions & 2 deletions _layouts/post.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,24 @@
layout: default
---

<article class="post">
<article id='posts-content' class="post">
<h1 class="post-title">{{ page.title }}</h1>
<time datetime="{{ page.date | date_to_xmlschema }}" class="post-date">{{ page.date | date_to_string }}</time>
{{ content }}
<p><small id="page_view">&nbsp;</small></p>
<div class="pagination">
{% if page.previous.url %}

<a id="next-page" class="pagination-item older" href="{{ page.previous.url }}">Older</a>
{% else %}
<span class="pagination-item older">Older</span>
{% endif %}
{% if page.next.url %}
<a class="pagination-item newer" href="{{ page.next.url }}">Newer</a>
{% else %}
<span class="pagination-item newer">Newer</span>
{% endif %}
</div>
</article>

{% if site.related_posts != empty %}
Expand All @@ -25,4 +38,4 @@ <h3>Related posts</h3>
</aside>
{% endif %}

<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
{% include inf.html %}
10 changes: 5 additions & 5 deletions index.html
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
title: Home
---

<div class="posts">
<div id="posts-content" class="posts">
{% for post in paginator.posts %}
<article class="post">
<h1 class="post-title">
Expand All @@ -18,11 +18,10 @@ <h1 class="post-title">
<p><small id="page_view">&nbsp;</small></p>
</article>
{% endfor %}
</div>

<div class="pagination">
<div class="pagination">
{% if paginator.next_page %}
<a class="pagination-item older" href="{{ paginator.next_page_path | prepend: site.baseurl }}">Older</a>
<a id="next-page" class="pagination-item older" href="{{ paginator.next_page_path | prepend: site.baseurl }}">Older</a>
{% else %}
<span class="pagination-item older">Older</span>
{% endif %}
Expand All @@ -31,6 +30,7 @@ <h1 class="post-title">
{% else %}
<span class="pagination-item newer">Newer</span>
{% endif %}
</div>
</div>

<script async src="//platform.twitter.com/widgets.js" charset="utf-8"></script>
{% include inf.html %}

0 comments on commit 6a16c2b

Please sign in to comment.