mirror of
				https://github.com/ZetaKebab/kesper.git
				synced 2025-11-04 08:09:49 +00:00 
			
		
		
		
	Remove infinitescroll in single page (#319)
* Remove infinitescroll in single page * Update infinitescroll.js
This commit is contained in:
		@@ -1,18 +1,29 @@
 | 
			
		||||
// Code snippet inspired by https://github.com/douglasrodrigues5/ghost-blog-infinite-scroll
 | 
			
		||||
$().ready(function () {
 | 
			
		||||
    var page = 2,
 | 
			
		||||
        blogUrl = window.location,
 | 
			
		||||
$(function ($) {
 | 
			
		||||
    var currentPage = 1,
 | 
			
		||||
        pathname = window.location.pathname,
 | 
			
		||||
        $window = $(window),
 | 
			
		||||
        $document = $(document),
 | 
			
		||||
        $result = $('.post-feed');
 | 
			
		||||
 | 
			
		||||
    $(window).scroll(function () {
 | 
			
		||||
        if ($(window).scrollTop() + $(window).height() == $(document).height()) {
 | 
			
		||||
            if (page <= maxPages) {
 | 
			
		||||
                $.get((blogUrl + '/page/' + page),
 | 
			
		||||
                function (content) {
 | 
			
		||||
                    $result.append($(content).find('.post').hide().fadeIn(100));
 | 
			
		||||
                    page = page + 1;
 | 
			
		||||
                });
 | 
			
		||||
            }
 | 
			
		||||
    function handleScroll () {
 | 
			
		||||
        // return if not scroll to the bottom
 | 
			
		||||
        if ($window.scrollTop() + $window.height() !== $document.height()) {
 | 
			
		||||
            return;
 | 
			
		||||
        }
 | 
			
		||||
    });
 | 
			
		||||
 | 
			
		||||
        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');
 | 
			
		||||
});
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user