Archived
1
0
This repository has been archived on 2020-12-10. You can view files and clone it, but cannot push or open issues or pull requests.
old/assets/js/post_feed.js

55 lines
1.5 KiB
JavaScript
Raw Normal View History

2018-10-16 16:28:42 +00:00
let offset = 0;
const amount = 10;
let firstRun = true;
let itemsLeft = true;
let running = false;
let loadingUrl;
if(window.location.pathname.indexOf('popular') !== -1) {
loadingUrl = '/posts/getPopularPosts';
2018-10-16 16:28:42 +00:00
} else {
loadingUrl = '/posts/getFeedPosts';
2018-10-16 16:28:42 +00:00
}
function loadEntries() {
if(!running && itemsLeft) {
$.ajax({
url: loadingUrl,
data: {
amount: amount,
offset: offset
},
beforeSend: function () {
$('.loading-spinner').show();
running = true;
},
success: function (data) {
$('.loading-spinner').hide();
$('.post-container .comment-list').append(data);
registerPostEvents();
offset++;
if (data === "") {
$('.post-container').append("<p>Es konnten keine weiteren Posts gefunden werden. Bitte schaue später nochmal vorbei!</p>");
itemsLeft = false;
}
firstRun = false;
running = false;
},
error: console.log
});
}
}
$(window).scroll(function() {
if($(document).scrollTop() + 360 + $(window).height() >= $('.comment-list').position().top + $('.comment-list').outerHeight()) {
loadEntries();
}
});
loadEntries();
$('.search-input').focus(function(){
$(this).parent().addClass('focus');
}).blur(function(){
$(this).parent().removeClass('focus');
});