Cutting stuff out.
[wolnelektury.git] / src / catalogue / static / 2022 / book / filter.js
index 59e810a..2ff4262 100644 (file)
@@ -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);
         $(".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;
                 }, 200);
             }
         }, 200);
-    });
+    }
     
 })(jQuery);