1111{{ partial "overview_block.html" .}}
1212
1313< style >
14+
15+ .search-overlay {
16+ cursor : pointer;
17+ position : fixed;
18+ top : 0 ;
19+ left : 0 ;
20+ width : 100% ;
21+ height : 200vh ;
22+ background-color : rgba (0 , 0 , 0 , 0.35 );
23+ z-index : 1000 ;
24+ }
25+
1426 .algolia-search {
27+ z-index : 5000 ;
28+ position : relative;
1529 .search-panel {
16- display : flex ;
30+ display : block ;
1731 }
1832
1933 .search-panel__results {
6882 }
6983</ style >
7084<!-- Search -->
85+ < div class ="search-overlay d-none "> </ div >
7186< section class ="section color-blue ">
7287 < div class ="container algolia-search rounded-lg ">
7388 < div class ="row ">
@@ -81,7 +96,6 @@ <h2 class="pt-5 color-blue">Search</h2>
8196 < div class ="search-panel__results d-block ">
8297 < div id ="searchbox "> </ div >
8398 < div id ="hits "> </ div >
84- < div id ="pagination "> </ div >
8599 </ div >
86100 </ div >
87101 </ div >
@@ -92,63 +106,69 @@ <h2 class="pt-5 color-blue">Search</h2>
92106< script src ="
https://cdn.jsdelivr.net/npm/[email protected] /dist/algoliasearch-lite.umd.js "
> </ script > 93107< script src ="
https://cdn.jsdelivr.net/npm/[email protected] "
> </ script > 94108< script >
95- const { algoliasearch, instantsearch } = window ;
96-
97- const searchClient = algoliasearch (
98- 'R5LXP5NUID' ,
99- '4b504b6988d05a7631d6a330fb7afa58'
100- ) ;
101-
102- const search = instantsearch ( {
103- indexName : 'website_pages' ,
104- searchClient,
105- future : { preserveSharedStateOnUnmount : true } ,
106- searchFunction : function ( helper ) {
107- if ( helper . state . query === '' ) {
108- return ;
109+ docReady ( function ( ) {
110+ const { algoliasearch, instantsearch } = window ;
111+
112+ const searchClient = algoliasearch (
113+ 'R5LXP5NUID' ,
114+ '4b504b6988d05a7631d6a330fb7afa58'
115+ ) ;
116+
117+ const search = instantsearch ( {
118+ indexName : 'website_pages' ,
119+ searchClient,
120+ future : { preserveSharedStateOnUnmount : true } ,
121+ searchFunction : function ( helper ) {
122+ if ( helper . state . query === '' ) {
123+ return ;
124+ }
125+
126+ helper . search ( ) ;
109127 }
110- helper . search ( ) ;
111- }
112- } ) ;
113-
114- let lastRenderArgs ;
115-
116- const infiniteHits = instantsearch . connectors . connectInfiniteHits (
117- ( renderArgs , isFirstRender ) => {
118- const { items, showMore, widgetParams } = renderArgs ;
119- const { container } = widgetParams ;
120-
121- lastRenderArgs = renderArgs ;
122-
123- if ( isFirstRender ) {
124- const sentinel = document . createElement ( 'div' ) ;
125- const containerDiv = document . createElement ( 'div' ) ;
126- containerDiv . className = 'ais-Hits' ;
127- const containerOl = document . createElement ( 'ol' ) ;
128- containerOl . className = 'ais-Hits-list' ;
129- containerDiv . appendChild ( containerOl ) ;
130- container . appendChild ( containerDiv ) ;
131- container . appendChild ( sentinel ) ;
132-
133- const observer = new IntersectionObserver ( entries => {
134- entries . forEach ( entry => {
135- if ( entry . isIntersecting
136- && ! lastRenderArgs . isLastPage
137- && $ ( document . activeElement ) ?. attr ( "class" ) === "ais-SearchBox-input" ) {
138- showMore ( ) ;
139- }
128+ } ) ;
129+
130+ let lastRenderArgs ;
131+
132+ const infiniteHits = instantsearch . connectors . connectInfiniteHits (
133+ ( renderArgs , isFirstRender ) => {
134+ const { items, showMore, widgetParams } = renderArgs ;
135+ const { container } = widgetParams ;
136+
137+ lastRenderArgs = renderArgs ;
138+
139+ if ( isFirstRender ) {
140+ const sentinel = document . createElement ( 'div' ) ;
141+ const containerDiv = document . createElement ( 'div' ) ;
142+ containerDiv . className = 'ais-Hits' ;
143+ const containerOl = document . createElement ( 'ol' ) ;
144+ containerOl . className = 'ais-Hits-list' ;
145+ containerDiv . appendChild ( containerOl ) ;
146+ container . appendChild ( containerDiv ) ;
147+ container . appendChild ( sentinel ) ;
148+ const observer = new IntersectionObserver ( entries => {
149+ entries . forEach ( entry => {
150+ if ( entry . isIntersecting
151+ && ! lastRenderArgs . isLastPage ) {
152+ showMore ( ) ;
153+ }
154+ } ) ;
140155 } ) ;
141- } ) ;
142156
143- observer . observe ( sentinel ) ;
157+ observer . observe ( sentinel ) ;
144158
145- return ;
146- }
159+ return ;
160+ }
161+
162+ const searchInput = $ ( ".ais-SearchBox-input" ) ;
163+ if ( ! searchInput . is ( ":focus" ) ) {
164+ container . querySelector ( 'ol' ) . innerHTML = "" ;
165+ return ;
166+ }
147167
148- container . querySelector ( 'ol' ) . innerHTML = items
149- . map (
150- item => {
151- return `
168+ container . querySelector ( 'ol' ) . innerHTML = items
169+ . map (
170+ item => {
171+ return `
152172 <li class="ais-Hits-item">
153173 <a href=${ item . url } class="container">
154174 <div class="row search-result-row">
@@ -165,25 +185,46 @@ <h3 class="color-blue search-result-title">${item.title}</h3>
165185 </a>
166186 </li>
167187 ` ;
168- } )
169- . join ( '' ) ;
170- }
171- ) ;
172- search . addWidgets ( [
173- instantsearch . widgets . searchBox ( {
174- container : '#searchbox' ,
175- } ) ,
176- instantsearch . widgets . configure ( {
177- hitsPerPage : 3 ,
178- filters : "language:{{$.Site.Language.Lang}}"
179- } ) ,
180- infiniteHits ( {
181- container : document . querySelector ( '#hits' ) ,
182- } ) ,
183- ] ) ;
184-
185-
186- search . start ( ) ;
188+ } )
189+ . join ( '' ) ;
190+ }
191+ ) ;
192+ search . addWidgets ( [
193+ instantsearch . widgets . searchBox ( {
194+ container : '#searchbox' ,
195+ placeholder : '{{ i18n "search-type-to-start" }}' ,
196+ } ) ,
197+ instantsearch . widgets . configure ( {
198+ hitsPerPage : 3 ,
199+ filters : "language:{{$.Site.Language.Lang}}"
200+ } ) ,
201+ infiniteHits ( {
202+ container : document . querySelector ( '#hits' ) ,
203+ } ) ,
204+ ] ) ;
205+
206+
207+ search . start ( ) ;
208+ } ) ;
209+ </ script >
210+ < script >
211+ docReady ( function ( ) {
212+ $ ( "input.ais-SearchBox-input" ) . on ( "focus" , function ( ) {
213+ $ ( ".algolia-search" ) . addClass ( "bg-lightblue" ) ;
214+ $ ( "#hits" ) . addClass ( "d-block" ) ;
215+ $ ( "#hits" ) . removeClass ( "d-none" ) ;
216+ $ ( ".search-overlay" ) . removeClass ( "d-none" ) ;
217+ $ ( ".search-overlay" ) . addClass ( "d-block" ) ;
218+ } ) ;
219+
220+ $ ( ".search-overlay" ) . on ( "click" , function ( ) {
221+ $ ( ".algolia-search" ) . removeClass ( "bg-lightblue" ) ;
222+ $ ( "#hits" ) . removeClass ( "d-block" ) ;
223+ $ ( "#hits" ) . addClass ( "d-none" ) ;
224+ $ ( ".search-overlay" ) . addClass ( "d-none" ) ;
225+ $ ( ".search-overlay" ) . removeClass ( "d-block" ) ;
226+ } ) ;
227+ } ) ;
187228</ script >
188229<!-- /Search -->
189230
0 commit comments