Skip to content

Instantly share code, notes, and snippets.

@Patrick64
Created June 4, 2019 10:41
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 Patrick64/64e7a0b241e13940cbffb8cc493c69dd to your computer and use it in GitHub Desktop.
Save Patrick64/64e7a0b241e13940cbffb8cc493c69dd to your computer and use it in GitHub Desktop.
function loadMoreButton() {
if ($('.listing-load-more-button').length>0) {
function loadMore(btn) {
var loadingElement = btn.parent().find('.loading');
loadingElement.show();
btn.remove();
var href = btn.attr('href');
$.get(btn.attr('href'),function(data) {
var newItems = /<!\-\-ITEMSBEGIN\-\->(.*)?<!\-\-ITEMSEND\-\->/s.exec(data)[0];
loadingElement.remove();
$('.listing-container').append(newItems);
});
}
$('.listing-container').on('click','.listing-load-more-button',function(e) {
e.preventDefault();
var btn = $(this);
loadMore(btn);
})
$(window).scroll(function(e) {
if (isScrolledIntoView($('.listing-load-more-button'))) {
loadMore($('.listing-load-more-button'));
}
})
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment