DataCCIW

Search Settings - PageListAsBlocksDepthTwo

Jan 6th, 2022 (edited)
867
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. {%- comment -%}
  2.    Authors: Tony V., Jeff R.
  3.    Last Update: 1-6-22
  4.    Summary: Similar to the core PageListAsBlocks template but designed to display children and grandchildren pages
  5.    Search functionality has also been added
  6. {%- endcomment -%}
  7.  
  8.  
  9. {%- javascript -%}
  10. $(document).ready(function()
  11. {
  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.     {
  15.         if (e.keyCode == 13)
  16.         {
  17.             e.preventDefault();
  18.             return false;
  19.         }
  20.     });
  21.  
  22.     // Filter page links when Search box is updated, value of text is not updated until after keyup
  23.     $('#pageSearch').on('keyup', function()
  24.     {
  25.         var value = $(this).val().toLowerCase();
  26.         // Filter page links when Search box is updated
  27.         $('.panel-body ul li').filter(function()
  28.         {
  29.             $(this).toggle($(this).text().toLowerCase().indexOf(value) > -1);
  30.         });
  31.  
  32.         // hides/reveals panel based on the presence of search results
  33.         $('.panel-body ul').each(function(index)
  34.         {
  35.             $(this).parent().parent().show(); // reset visibilty of panels
  36.             if ($(this).children(':visible').length == 0)
  37.             {
  38.                 //if a panel has no visible children then hide it
  39.                 $(this).parent().parent().hide();
  40.             }
  41.         });
  42.     });
  43. });
  44. {%- endjavascript -%}
  45.  
  46. {%- stylesheet -%}
  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>
  55. </div>
  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.  
Add Comment
Please, Sign In to add comment