Skip to content
This repository has been archived by the owner on Nov 12, 2021. It is now read-only.

Commit

Permalink
Hotfix: Fixes bug iwth "Load More"-button not appearing
Browse files Browse the repository at this point in the history
Fixes #102
  • Loading branch information
Gustav Lindqvist authored Jul 6, 2018
1 parent ff8c36a commit ae64cc8
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions assets/js/scripts.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@

loadMorePosts: function(event){
var $masonry = this.$masonry;

var that = this;
event.preventDefault();

// Are there more posts to load?
Expand All @@ -208,21 +208,22 @@
$.get(this.nextLink, function(data){
// Append all posts to #content
var posts = $(data).find('.post');

$.each(posts,function(){
$(this).css('opacity', 0);
});
$masonry.append(posts);
// Change nextLink to next page
$('#feed').imagesLoaded(function(){
this.pageNum++;
that.pageNum++;
// Prevent error on "load more" when there is only one extra page
if ('nextLink' in this){
this.nextLink = this.nextLink.substring(0, this.nextLink.indexOf('page/'));
this.nextLink += 'page/'+(this.pageNum+1);
if ('nextLink' in that){
that.nextLink = that.nextLink.substring(0, that.nextLink.indexOf('page/'));
that.nextLink += 'page/'+(that.pageNum+1);
}

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

0 comments on commit ae64cc8

Please sign in to comment.