Skip to content

Instantly share code, notes, and snippets.

@domagude
Created November 4, 2017 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save domagude/8e52d77c953a2df735cc3189df1a1547 to your computer and use it in GitHub Desktop.
Save domagude/8e52d77c953a2df735cc3189df1a1547 to your computer and use it in GitHub Desktop.
$(document).on('turbolinks:load', function() {
var isLoading = false;
if ($('.infinite-scroll', this).size() > 0) {
$(window).on('scroll', function() {
var more_posts_url = $('.pagination a.next_page').attr('href');
var threshold_passed = $(window).scrollTop() > $(document).height() - $(window).height() - 60;
if (!isLoading && more_posts_url && threshold_passed) {
isLoading = true;
$.getScript(more_posts_url).done(function (data,textStatus,jqxhr) {
isLoading = false;
}).fail(function() {
isLoading = false;
});
}
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment