Показать сообщение отдельно
  #7 (permalink)  
Старый 12.04.2020, 21:33
Аватар для рони
Профессор
Отправить личное сообщение для рони Посмотреть профиль Найти все сообщения от рони
 
Регистрация: 27.05.2010
Сообщений: 33,072

rootcamp,

(function($)
   {
     $.fn.extend(
       {
       search: function(callback, timeout) {
           timeout = timeout || 100;
           var timeoutReference,
           search = function(el) {
             if (!timeoutReference) return;
             timeoutReference = null;
             callback.call(el);
           };
           return this.each(function(i, el)
             {
               var $el = $(el);
               $el.is(':input') && $el.on('keyup keydown', function(e)
                 {
                   if (e.type=='keyup' && e.keyCode==8) return;
                   console.log(e.which);
                   if (timeoutReference) clearTimeout(timeoutReference);
                   timeoutReference = setTimeout(function()
                     {
                       var valor = el.value.toLowerCase();
                       console.log(valor);
                       if(valor.length) {
                         const dis = $(".containerItems .row [data-search*='" + valor + "']").length;
                         $('.containerItems .row').each(function(i, e)
                           {
                             const one = $(e).children('div[data-search*="'+valor+'"]');
                             if(one.length > 0) {
                               $(e).stop().fadeIn("fast");
                               $(e).children().stop().fadeIn("fast");
                               $(e).children('div.alphabet-line ~ div:not([data-search*="'+valor+'"])').stop().fadeOut("fast");
                             }else {
                               $(e).stop().fadeOut("fast");
                               $(e).children().stop().fadeOut("fast");
                             }
                           }
                         );
                         $('.reser').text("Показано : "+dis+" по запросу " + valor).stop().fadeIn("fast");
                       }else {
                         $('.reser').text("Показано : Все").stop().fadeIn("fast");
                         $(".containerItems .row").stop().fadeIn("fast");
                         $(".containerItems .row").children().stop().fadeIn("fast");
                         return;
                       }
                       search(el);
                       // console.log(el);
                     }, timeout
                   );
                 }
               ).on('blur', function() {
                   //when leaving the input
                   $(".containerItems .row").stop().fadeIn("slow");
                   $(".containerItems .row").children().stop().fadeIn("slow");
                   search(el);
                 }
               );
             }
           );
         }
       }
     );
   }
 )(jQuery);
Ответить с цитированием