15d4e34922acf5959eb9f396bb0f01c892708f84
[wolnelektury.git] / src / catalogue / static / 2022 / book / filter.js
1 (function($) {
2
3     $(".quick-filter").each(function() {
4         let bookList = $('#' + $(this).data('for'));
5         $(this).on('input propertychange', function() {
6             let search = $(this).val().toLowerCase();
7             bookList.children().each(function() {
8                 found = !search || $("h2", this).text().toLowerCase().search(search) != -1;
9                 if (found) 
10                     $(this).fadeIn();
11                 else
12                     $(this).fadeOut();
13             });
14         });
15     });
16
17     $(".l-books__sorting button").on('click', function() {
18         if ($(this).hasClass('is-active')) return;
19         $(".is-active", $(this).parent()).removeClass("is-active");
20         $(this).addClass("is-active");
21         let prop = $(this).attr('data-order');
22         $(".l-books__item").css('opacity', '0');
23         setTimeout(function() {
24             if (prop) {
25                 $(".l-books__item").each(function() {
26                     $(this).css('order', $(this).attr(prop));
27                 });
28             } else {
29                 $(".l-books__item").css('order', '');
30             }
31             setTimeout(function() {
32                 $(".l-books__item").css('opacity', '100%');
33             }, 200);
34         }, 200);
35     });
36     
37 })(jQuery);