Moving forward.
[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
7         $(this).on('focus', function() {
8             filterList.addClass('filters-enabled');
9         });
10         $(this).on('blur', function() {
11             filterList.removeClass('filters-enabled');
12         });
13
14         $(this).on('input propertychange', function() {
15             let search = $(this).val().toLowerCase();
16
17             bookList.children().each(function() {
18                 found = !search ||
19                     $(".s", this).text().toLowerCase().search(search) != -1
20                     ;
21                 if (found) 
22                     $(this).fadeIn();
23                 else
24                     $(this).fadeOut();
25             });
26
27
28
29             $('.filter-container', filterList).children().each(function() {
30                 console.log($(this).text().toLowerCase());
31                 found = !search ||
32                     $(this).text().toLowerCase().search(search) != -1
33                     ;
34                 if (found) 
35                     $(this).fadeIn();
36                 else
37                     $(this).fadeOut();
38             });
39         });
40
41     });
42
43     $(".l-books__sorting button").on('click', function() {
44         if ($(this).hasClass('is-active')) return;
45         $(".is-active", $(this).parent()).removeClass("is-active");
46         $(this).addClass("is-active");
47         let prop = $(this).attr('data-order');
48         $(".l-books__item").css('opacity', '0');
49         setTimeout(function() {
50             if (prop) {
51                 $(".l-books__item").each(function() {
52                     $(this).css('order', $(this).attr(prop));
53                 });
54             } else {
55                 $(".l-books__item").css('order', '');
56             }
57             setTimeout(function() {
58                 $(".l-books__item").css('opacity', '100%');
59             }, 200);
60         }, 200);
61     });
62     
63 })(jQuery);