X-Git-Url: https://git.mdrn.pl/wolnelektury.git/blobdiff_plain/ea9d7d13a44a6ad6357b1af8c977c27753268521..ddf2102eff7ea420a4ea5144c43409587fc1156e:/src/catalogue/static/2022/book/filter.js diff --git a/src/catalogue/static/2022/book/filter.js b/src/catalogue/static/2022/book/filter.js index 59e810a48..2ff426234 100644 --- a/src/catalogue/static/2022/book/filter.js +++ b/src/catalogue/static/2022/book/filter.js @@ -8,10 +8,17 @@ function get_page(page, search, ordering, callback) { get_page_by_url('.?page=' + page + '&order=' + ordering + '&search=' + search, callback); } + + let lastFulfilledPage = 0; + function get_page_by_url(url, callback) { + let requestTime = + new Date(); $.get( url, function(data) { + if (lastFulfilledPage > requestTime) return; + lastFulfilledPage = requestTime; + html = $(data); objectList = $('#object-list', html); paginate = $('#paginate', html); @@ -88,8 +95,19 @@ $(".is-active", $(this).parent()).removeClass("is-active"); $(this).addClass("is-active"); let prop = $(this).attr('data-order'); + $(".l-books__sorting select").val(prop); + if (prop == '-') prop = ''; + resort(prop); + }); + $(".l-books__sorting select").on('change', function() { + let prop = $(this).val(); + $(".is-active", $(this).parent()).removeClass("is-active"); + $("[data-order='" + prop +"']", $(this).parent()).addClass("is-active"); + if (prop == '-') prop = ''; + resort(prop); + }); - + function resort(prop) { // do we NOW have pages (possibly after filtering)? // if we don't have pages, we can just sort here. let havePages = $('.l-pagination li').length > 0; @@ -111,6 +129,6 @@ }, 200); } }, 200); - }); + } })(jQuery);