File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 3939 ' webinars' : ' Webinars' ,
4040 }
4141 const placeholder = Object .prototype .hasOwnProperty .call (scopeTitles, searchScope) ? ` Search in ${ scopeTitles[searchScope]} ...` : ' Search...'
42-
42+ const initialHitsPerPage = 5 ;
43+
44+ let hitsPerPage = initialHitsPerPage
45+ let initialQuery = ' ' ;
46+
4347 const searchQuery = (searchClient , query , scope ) => {
48+ initialQuery = query
49+
4450 return {
4551 sourceId : scope,
4652 getItems : () => getAlgoliaResults ({
5056 indexName : ' netlify_00f8cf60-997f-4c4d-9427-a97924358648_live_all' ,
5157 params : {
5258 query,
53- hitsPerPage: 5 ,
59+ hitsPerPage
5460 },
5561 attributesToHighlight: ' *' ,
5662 filters: scope .length === 0 ? undefined : ` category:${ scope} `
104110 </div >
105111 </a >` ;
106112 },
113+ footer ({html}) {
114+ return html ` <button id =" load-more" class =" aa-LoadMore" >Load more...</button >` ;
115+ }
107116 }
108117 };
109118 }
110119
111120 autocomplete ({
112- debug: true ,
121+ debug: false ,
113122 container: ' #algolia-search' ,
114123 placeholder,
115124 getSources ({query}) {
127136 document .querySelectorAll (' .aa-Panel img' ).forEach (img => {
128137 img .src = img .getAttribute (' data-src' );
129138 });
139+
140+ // reset the number of results per page if the query changes
141+ if (state .query !== initialQuery) {
142+ hitsPerPage = initialHitsPerPage
143+ }
144+
145+ const loadMoreBtn = document .querySelector (' #load-more' );
146+ if (loadMoreBtn) {
147+ loadMoreBtn .onclick = () => {
148+ hitsPerPage += initialHitsPerPage;
149+
150+ const input = document .querySelector (' #algolia-search input' );
151+
152+ // Trick Autocomplete into refreshing and retrieving more hits per page
153+ input .dispatchEvent (new Event (' input' , { bubbles: true }));
154+ };
155+ }
130156 }
131157 });
132158 }
Original file line number Diff line number Diff line change 8383.aa-Panel .aa-ItemContent .aa-ItemContentBody .aa-ItemContentDescription {
8484 color : # 777 ;
8585}
86+
87+ .aa-Panel .aa-SourceFooter # load-more {
88+ display : block;
89+ width : 100% ;
90+ text-align : center;
91+ color : # 777 ;
92+ padding : 10px 0 5px ;
93+ font-size : 12px ;
94+ }
95+
96+ .aa-Panel .aa-SourceFooter # load-more : hover {
97+ cursor : pointer;
98+ color : # 2563eb ;
99+ }
You can’t perform that action at this time.
0 commit comments