Jargs

Search Settings - PageListAsBlocks

Jan 4th, 2022 (edited)
476
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {%- javascript -%}
  2. $(document).ready(function()
  3. {
  4.     var $panel = $('.search-target .panel-body'),
  5.         $noMatches = $('<div class="no-matches alert alert-info">No matches found</div>');
  6.  
  7.     $noMatches.hide();
  8.     $panel.prepend($noMatches);
  9.  
  10.     $('#pageSearch')
  11.         // prevent the enter key from submitting the form
  12.         .on('keydown', function(e)
  13.         {
  14.             if (e.keyCode == 13)
  15.             {
  16.                 e.preventDefault();
  17.                 return false;
  18.             }
  19.         })
  20.         // Filter page links when Search box is updated
  21.         .on('keyup', function(e)
  22.         {
  23.             var value = $(this).val().toLowerCase();
  24.                 $matched = $('.panel-body > ul > li').filter(function()
  25.                 {
  26.                     var $setting = $(this),
  27.                         isShown = $setting.is(':visible'),
  28.                         isMatch = $setting.text().toLowerCase().indexOf(value) > -1;
  29.  
  30.                     $setting.toggleClass('match', isMatch);
  31.  
  32.                     if (isMatch && !isShown) $setting.stop(true,false).show(400);
  33.                     else if (!isMatch && isShown) $setting.stop(true,false).hide(400);
  34.  
  35.                     return isMatch;
  36.                 }),
  37.                 matchCount = $matched.length;
  38.  
  39.             $noMatches.toggle(matchCount == 0);
  40.         });
  41. });
  42. {%- endjavascript -%}
  43.  
  44. {%- stylesheet -%}
  45.     #pageSearch { margin-bottom:15px; }
  46. {% endstylesheet %}
  47.  
  48. <div class="form-inline">
  49.     <div class="form-group">
  50.         <input id="pageSearch" type="text" class="form-control input-sm" placeholder="Search&hellip;">
  51.     </div>
  52. </div>
  53.  
  54. <div class="search-target">
  55. {%- include '~~/Assets/Lava/PageListAsBlocks.lava' -%}
  56. </div>
  57.  
Add Comment
Please, Sign In to add comment