View difference between Paste ID: n0jBY3yS and FbwSjjsM
SHOW: | | - or go back to the newest paste.
1
{%- comment -%}
2
   Authors: Tony V., Jeff R.
3
   Last Update: 1-6-22
4-
    var $panel = $('.search-target .panel-body'),
4+
   Summary: Similar to the core PageListAsBlocks template but designed to display children and grandchildren pages
5-
        $noMatches = $('<div class="no-matches alert alert-info">No matches found</div>');
5+
   Search functionality has also been added
6
{%- endcomment -%}
7-
    $noMatches.hide();
7+
8-
    $panel.prepend($noMatches);
8+
9
{%- javascript -%}
10-
    $('#pageSearch')
10+
11-
        // prevent the enter key from submitting the form
11+
12-
        .on('keydown', function(e)
12+
    // Prevent async page submission triggered by enter key which breaks script, preventing submission after keyup does not work
13
    $('#pageSearch').on('keydown', function(e)
14-
            if (e.keyCode == 13)
14+
    {
15
        if (e.keyCode == 13)
16-
                e.preventDefault();
16+
17-
                return false;
17+
            e.preventDefault();
18
            return false;
19-
        })
19+
        }
20
    });
21-
        .on('keyup', function(e)
21+
22
    // Filter page links when Search box is updated, value of text is not updated until after keyup
23-
            var value = $(this).val().toLowerCase();
23+
    $('#pageSearch').on('keyup', function()
24-
                $matched = $('.panel-body > ul > li').filter(function()
24+
    {
25-
                {
25+
        var value = $(this).val().toLowerCase();
26-
                    var $setting = $(this),
26+
27-
                        isShown = $setting.is(':visible'),
27+
        $('.panel-body ul li').filter(function()
28-
                        isMatch = $setting.text().toLowerCase().indexOf(value) > -1;
28+
29
            $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
30-
                    $setting.toggleClass('match', isMatch);
30+
31
32-
                    if (isMatch && !isShown) $setting.stop(true,false).show(400);
32+
        // hides/reveals panel based on the presence of search results
33-
                    else if (!isMatch && isShown) $setting.stop(true,false).hide(400);
33+
        $('.panel-body ul').each(function(index)
34
        {
35-
                    return isMatch;
35+
            $(this).parent().parent().show(); // reset visibilty of panels
36-
                }),
36+
            if ($(this).children(':visible').length == 0)
37-
                matchCount = $matched.length;
37+
38
                //if a panel has no visible children then hide it
39-
            $noMatches.toggle(matchCount == 0);
39+
                $(this).parent().parent().hide();
40
            }
41
        });
42
    });
43
});
44
{%- endjavascript -%}
45
46-
{% endstylesheet %}
46+
47
    h2 { margin-left:10px; }
48
    #pageSearch { margin-bottom:15px; }
49
{%- endstylesheet -%}
50
51
<div class="form-inline">
52
    <div class="form-group">
53
        <input id="pageSearch" type="text" class="form-control input-sm" placeholder="Search&hellip;">
54-
<div class="search-target">
54+
55-
{%- include '~~/Assets/Lava/PageListAsBlocks.lava' -%}
55+
56
57
{%- for childPage in Page.Pages -%}
58
    {%- if  childPage.Title != 'All Settings' -%}
59
        <div class="panel panel-default list-as-blocks clearfix">
60
            <div class="panel-heading">
61
                <h2 class="panel-title"><i class="{{ childPage.IconCssClass }}"></i> {{ childPage.Title }}</h2>
62
            </div>
63
            <div class="panel-body">
64
                <ul>
65
                    {%- for grandChildPage in childPage.Pages -%}
66
                        <li>
67
                            <a href="{{ grandChildPage.Url }}" {%- if grandChildPage.DisplayDescription != 'true' -%} title="{{ grandChildPage.Description }}"{%- endif -%}>
68
                                {%- if grandChildPage.IconCssClass != '' -%}
69
                                    <i class="{{ grandChildPage.IconCssClass }}"></i>
70
                                {%- endif -%}
71
                                <h3>{{ grandChildPage.Title }}</h3>
72
                            </a>
73
                        </li>
74
                    {%- endfor -%}
75
                </ul>
76
            </div>
77
        </div>
78
    {%- endif -%}
79
{%- endfor -%}
80
81
{%- if IncludePageList != empty -%}
82
<div class="panel panel-default list-as-blocks clearfix">
83
    <div class="panel-heading"><h2 class="panel-title">Additional Pages</h2></div>
84
    <div class="panel-body">
85
        <ul>
86
            {%- for includedPage in IncludePageList -%}
87
                {%- assign attributeParts = includedPage | PropertyToKeyValue -%}
88
                <li>
89
                    <a href="{{ attributeParts.Value }}">{{ attributeParts.Key }}</a>
90
                </li>
91
            {%- endfor -%}
92
        </ul>
93
    </div>
94
</div>
95
{%- endif -%}
96