var page = 1;
var totalPages = 1;
var canLoad = 1 ;
/* Moving this within a conditional to be called only if element exists. Causes errors otherwise */
var $listContainer = $('.content-container');
if($listContainer){
$(window).scroll(function(){
var resultsBottom = $listContainer.height() + $listContainer.offset().top;
var distanceToTop = (resultsBottom - $(window).scrollTop());
var windowHeight = $(window).height();
if(canLoad == 1 && page <= totalPages){
if(distanceToTop < windowHeight) {
canLoad = 0;
page ++;
getArticles(page);
};
};
});
};
function getArticles(page){
var html = (function () {
var html = null;
$('.loading-spinner').show();
$.ajax({
'async': false,
'global': false,
'url': "/data/results/?listing_category=residential&listing_sale_method=Sale&listing_suburb_id=636&pg=" + page,
'success': function (data) {
html = data;
}
});
return html;
})();
$listContainer.find('ul').append('