SHOW:
|
|
- or go back to the newest paste.
| 1 | - | {%- comment -%}
|
| 1 | + | |
| 2 | - | Last Update: 1-6-22 |
| 2 | + | |
| 3 | - | Summary: Adds search functionality to the PageListAsBlocks lava template |
| 3 | + | |
| 4 | - | {%- endcomment -%}
|
| 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 | - | // Prevent async page submission triggered by enter key which breaks script, preventing submission after keyup does not work |
| 9 | + | |
| 10 | - | $('#pageSearch').on('keydown', function(e)
|
| 10 | + | $('#pageSearch')
|
| 11 | - | {
|
| 11 | + | // prevent the enter key from submitting the form |
| 12 | .on('keydown', function(e)
| |
| 13 | - | if (e.keyCode == 13) |
| 13 | + | |
| 14 | if (e.keyCode == 13) | |
| 15 | - | e.preventDefault(); |
| 15 | + | {
|
| 16 | - | return false; |
| 16 | + | e.preventDefault(); |
| 17 | - | } |
| 17 | + | return false; |
| 18 | - | }); |
| 18 | + | } |
| 19 | }) | |
| 20 | - | // Filter page links when Search box is updated, value of text is not updated until after keyup |
| 20 | + | // Filter page links when Search box is updated |
| 21 | - | $('#pageSearch').on('keyup', function(e)
|
| 21 | + | .on('keyup', function(e)
|
| 22 | - | {
|
| 22 | + | |
| 23 | - | var value = $(this).val().toLowerCase(); |
| 23 | + | var value = $(this).val().toLowerCase(); |
| 24 | - | $('.panel-body ul li').filter(function()
|
| 24 | + | $matched = $('.panel-body > ul > li').filter(function()
|
| 25 | {
| |
| 26 | - | $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1); |
| 26 | + | var $setting = $(this), |
| 27 | isShown = $setting.is(':visible'),
| |
| 28 | - | }); |
| 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 | - | {%- endstylesheet -%}
|
| 34 | + | |
| 35 | return isMatch; | |
| 36 | }), | |
| 37 | matchCount = $matched.length; | |
| 38 | ||
| 39 | $noMatches.toggle(matchCount == 0); | |
| 40 | }); | |
| 41 | }); | |
| 42 | - | {%- include '~~/Assets/Lava/PageListAsBlocks.lava' -%} |
| 42 | + | |
| 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…"> | |
| 51 | </div> | |
| 52 | </div> | |
| 53 | ||
| 54 | <div class="search-target"> | |
| 55 | {%- include '~~/Assets/Lava/PageListAsBlocks.lava' -%}
| |
| 56 | </div> | |
| 57 |