mirror of
https://github.com/ViViDboarder/Vivid-Casper.git
synced 2024-12-22 19:47:38 +00:00
Remove infinitescroll in single page (#319)
* Remove infinitescroll in single page * Update infinitescroll.js
This commit is contained in:
parent
96ffcdceed
commit
d3a9af0666
@ -1,18 +1,29 @@
|
|||||||
// Code snippet inspired by https://github.com/douglasrodrigues5/ghost-blog-infinite-scroll
|
// Code snippet inspired by https://github.com/douglasrodrigues5/ghost-blog-infinite-scroll
|
||||||
$().ready(function () {
|
$(function ($) {
|
||||||
var page = 2,
|
var currentPage = 1,
|
||||||
blogUrl = window.location,
|
pathname = window.location.pathname,
|
||||||
|
$window = $(window),
|
||||||
|
$document = $(document),
|
||||||
$result = $('.post-feed');
|
$result = $('.post-feed');
|
||||||
|
|
||||||
$(window).scroll(function () {
|
function handleScroll () {
|
||||||
if ($(window).scrollTop() + $(window).height() == $(document).height()) {
|
// return if not scroll to the bottom
|
||||||
if (page <= maxPages) {
|
if ($window.scrollTop() + $window.height() !== $document.height()) {
|
||||||
$.get((blogUrl + '/page/' + page),
|
return;
|
||||||
function (content) {
|
|
||||||
$result.append($(content).find('.post').hide().fadeIn(100));
|
|
||||||
page = page + 1;
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
});
|
|
||||||
|
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');
|
||||||
});
|
});
|
||||||
|
@ -63,10 +63,12 @@
|
|||||||
</script>
|
</script>
|
||||||
<script type="text/javascript" src="{{asset "js/jquery.fitvids.js"}}"></script>
|
<script type="text/javascript" src="{{asset "js/jquery.fitvids.js"}}"></script>
|
||||||
|
|
||||||
|
{{#if pagination.pages}}
|
||||||
<script>
|
<script>
|
||||||
var maxPages = parseInt('{{pagination.pages}}');
|
var maxPages = parseInt('{{pagination.pages}}');
|
||||||
</script>
|
</script>
|
||||||
<script src="{{asset "js/infinitescroll.js"}}"></script>
|
<script src="{{asset "js/infinitescroll.js"}}"></script>
|
||||||
|
{{/if}}
|
||||||
|
|
||||||
{{!-- The #block helper will pull in data from the #contentFor other template files. In this case, there's some JavaScript which we only want to use in post.hbs, but it needs to be included down here, after jQuery has already loaded. --}}
|
{{!-- The #block helper will pull in data from the #contentFor other template files. In this case, there's some JavaScript which we only want to use in post.hbs, but it needs to be included down here, after jQuery has already loaded. --}}
|
||||||
{{{block "scripts"}}}
|
{{{block "scripts"}}}
|
||||||
|
Loading…
Reference in New Issue
Block a user