2017-06-21 12:10:09 +00:00
|
|
|
// Code snippet inspired by https://github.com/douglasrodrigues5/ghost-blog-infinite-scroll
|
2017-06-27 11:03:51 +00:00
|
|
|
$(function ($) {
|
|
|
|
var currentPage = 1,
|
|
|
|
pathname = window.location.pathname,
|
|
|
|
$window = $(window),
|
|
|
|
$document = $(document),
|
2017-06-21 12:10:09 +00:00
|
|
|
$result = $('.post-feed');
|
|
|
|
|
2017-06-27 11:03:51 +00:00
|
|
|
function handleScroll () {
|
|
|
|
// return if not scroll to the bottom
|
|
|
|
if ($window.scrollTop() + $window.height() !== $document.height()) {
|
|
|
|
return;
|
2017-06-21 12:10:09 +00:00
|
|
|
}
|
2017-06-27 11:03:51 +00:00
|
|
|
|
|
|
|
if (currentPage >= maxPages) {
|
|
|
|
return $window.off('scroll', handleScroll);
|
|
|
|
}
|
|
|
|
|
|
|
|
// next page
|
|
|
|
currentPage++;
|
|
|
|
|
|
|
|
// Load more
|
|
|
|
$.get((pathname + 'page/' + currentPage + '/'), function (content) {
|
|
|
|
$result.append($(content).find('.post').hide().fadeIn(100));
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
$window.on('scroll', handleScroll).trigger('scroll');
|
2017-06-21 12:10:09 +00:00
|
|
|
});
|