Advertisement
Igor150195

Пример поиска

Nov 8th, 2023
1,020
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. $('.shop2-filter__item').each(function () {
  2.     let $this = $(this);
  3.     let $checkbox = $this.find('.shop2-filter__checkbox');
  4.     let $search = $this.find('.gr-multiselect_js .gr-multiselect__search');
  5.     let $search2 = $this.find('.gr-multiselect-2_js .gr-multiselect-2__search');
  6.     let searchWidth = $search.outerWidth();
  7.  
  8.     $search.on("keyup", function () {
  9.         filtrate($(this).val().toLowerCase(), $checkbox, 'gr-multiselect_hide_item');
  10.  
  11.         let thisLength = $(this).val().length;
  12.  
  13.         $(this).css({
  14.             "width": searchWidth + (thisLength * 10)
  15.         });
  16.     });
  17.  
  18.     if ($checkbox.length > shop2.my.gr_filter_multiselect_count) {
  19.         let $container = $(this).find('.gr-multiselect-2__container');
  20.         $container.addClass('show_multi_search');
  21.     };
  22.  
  23.     $search2.on("keyup", function () {
  24.         if ($(this).val() != "") {
  25.             $(this).addClass('active');
  26.         } else {
  27.             $(this).removeClass('active');
  28.         };
  29.         filtrate($(this).val().toLowerCase(), $checkbox, 'gr-multiselect-2_hide_item');
  30.     });
  31. });
  32.  
  33.  
  34. function filtrate(searched, $context, hideClass) {
  35.     $context.removeClass(hideClass);
  36.  
  37.     $context.each(function () {
  38.         var isHidden = $(this).data('content').toString().toLowerCase().indexOf(searched) > -1;
  39.  
  40.         if (!isHidden) {
  41.             $(this).addClass(hideClass);
  42.         };
  43.     });
  44. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement