Reedyn / Saga

A Ghost theme designed for photostories :sunrise_over_mountains:

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"Load more" button throwing error

spacedotworks opened this issue · comments

The "load more" button in the index page was throwing an error upon being pressed. Issue was traced to line 218 of scripts.js.

nextLink property appeared to be missing in this when there was only 1 extra page of posts. I had to add a property checker if('nextlLink' in this){} to prevent the error from occurring.

I ran into this as well

Your solution will fix the exception, but not the problem. This will fix it:

var self = this;
$.get(self.nextLink, function(data){ 
    // Append all posts to #content
    var posts = $(data).find('.post');
    $.each(posts,function(){
        $(self).css('opacity', 0);
    });
    $masonry.append(posts);
    // Change nextLink to next page
    $('#feed').imagesLoaded(function(){
    self.pageNum++;
    self.nextLink = self.nextLink.substring(0, self.nextLink.indexOf('page/'));
    self.nextLink += 'page/'+(self.pageNum+1);

    // Remove button if last page else move the button to end of #content
    if(self.pageNum < self.max) {
        $('#loadmore').insertAfter($('#feed .post:last'));
        $('#loadmore a').html("Load more <i class='fa fa-plus-circle'></i>");
    } else {
            $('#loadmore').remove();
    }
        $masonry.masonry('appended', posts);
    });
});