Home page and news page are finished

This commit is contained in:
Jorit Tijsen
2024-03-13 12:37:09 +01:00
parent 55aa88c0f6
commit 2895ba283b
58 changed files with 3713 additions and 31764 deletions

41
public/js/main.js vendored Normal file
View File

@@ -0,0 +1,41 @@
function loadMoreNews(e, _options) {
var options = $.extend( {
loadingElementId: '#loading'
}, _options );
window.loadMoreNews = window.loadMoreNewsSettings ?? {}
var nextPage = window.loadMoreNewsSettings.nextPage ?? 2;
var isLoading = window.loadMoreNewsSettings.isLoading ?? false;
var $isLoading = $(options.loadingElementId).hide();
e.preventDefault();
if (!isLoading) {
// Set flag and update UI
isLoading = 1;
$isLoading.show();
var $button = $(this).attr("disabled", "disabled");
// Fire request for the next page
$.ajax({url: document.location.pathname + '?pagina=' + nextPage})
.always(function () {
// Whether success or failure, update the UI again
isLoading = 0;
$isLoading.hide();
$button.removeAttr("disabled");
})
.done(function (data) {
if (!data) {
// When no data was returned, disable the button permanently
page = -1;
$button.attr("disabled", "disabled").text("Geen nieuws meer.");
return;
}
console.log($(data));
console.log($(data).find('#items-more-news'));
$('#items-more-news').append($(data).find('#items-more-news'));
$('#items-most-read').append($(data).find('#items-most-read'));
++nextPage;
});
}
}