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