(function ($) { /** * @param {object} _options */ $.fn.loadMoreNews = function (_options) { var isLoading = false; var page = 1; var options = { loadingElementId: '#loading', container: '', url: document.location.pathname, nextPage: 2, dateStart: null, dateEnd:null }; $.extend(options, _options); var $isLoading = $(options.loadingElementId, this); $isLoading.hide(); this.unbind('click').click(function (e) { e.preventDefault(); if (!isLoading) { // Set flag and update UI isLoading = 1; $isLoading.show(); var $button = $(this).attr("disabled", "disabled"); var $container = $(options.container); $container.each(function(){$(this).find('.no-results').remove();}); // Fire request for the next page $.ajax({url: options.url + (options.url.indexOf('?') >= 0 ? '&' : '?') + 'pagina=' + options.nextPage + (options.dateStart ? '&dateStart=' + options.dateStart : '') + (options.dateEnd ? '&dateEnd=' + options.dateEnd : '')}) .always(function () { // Whether success or failure, update the UI again isLoading = 0; $isLoading.hide(); $button.removeAttr("disabled"); $(options.container + ' .loader').remove(); }) .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; } $container.each(function () { var id = this.toString(); $(id).append($('