PageSourceSearch

https://high.org/wp-content/themes/icelander-child/assets/js/page-search.js?t=1790239378?ver=1.0.0

js high.org collected 2026-09-24 08:52:02 UTC 24,103 bytes, 778 lines download raw bytes

1/**
2 * Functions for the search field.
3 */
4
5const queryString = window.location.search;
6const urlParams = new URLSearchParams(queryString);
7
8const searchFieldElements = document.querySelectorAll('.at-search-component input[type="search"]');
9
10const collectionHighlightsPerPage = 12;
11
12let mapRoomContent = '';
13let mapTabFloorsURL = '';
14
15if (searchFieldElements) {
16	searchFieldElements.forEach((element) => {
17		if (element.value.length > 0) {
18			searchFieldUpdate(element);
19		}
20	});
21}
22
23function searchFieldUpdate (searchElement) {
24	closeButton = searchElement.nextElementSibling;
25
26	if (searchElement.value.length > 0) {
27		if (closeButton.classList.contains('disabled')) {
28			closeButton.classList.remove('disabled');
29		}
30	} else {
31		if (!closeButton.classList.contains('disabled')) {
32			closeButton.classList.add('disabled');
33		}
34	}
35}
36
37async function clearSearchField (clearButton) {
38	const searchFieldInput = clearButton.previousElementSibling;
39	const submitButton = clearButton.nextElementSibling;
40
41	searchFieldInput.value = '';
42	searchFieldUpdate(searchFieldInput);
43
44	if (submitButton) {
45		submitButton.click();
46	}
47}
48
49/**
50 * Global Search
51 */
52
53const notFoundMessage = 'No search results found. Please try again.';
54const notFoundHTML = '<div class="at-filters-component-results-counter-container"><p class="at-filters-component-results-counter">' + notFoundMessage + '</p></div>';
55
56const searchField = document.querySelector('#at-search-field');
57const paginationOutput = document.querySelector('#paginationOutput');
58
59const globalSearchQueryString = window.location.search;
60const globalSearchUrlParams = new URLSearchParams(globalSearchQueryString);
61
62let bodyData = {};
63let lastQuery = '';
64let globalPage = globalSearchUrlParams.get('page') ?? 1;
65
66// Create a new Custom Event to be attached to the Collection Date Pickers
67const collectionDatePicker = new CustomEvent("collectiondatepicker");
68
69const pageSearch = {
70	searchOutput: document.querySelector('#filtersOutput'),
71	allInputs: null,
72	collectionInputs: null,
73	exhibitionInputs: null,
74	eventsInputs: null,
75	teacherResourcesInput: null,
76	loadFunctionCollections: null,
77	inputCollections: null,
78	s: null,
79	rt: null,
80	filterByNames: {
81		ccf: 'collection-date-created-from',
82		cct: 'collection-date-created-to',
83		caf: 'collection-date-acquired-from',
84		cat: 'collection-date-acquired-to',
85		obj: 'obj-type',
86		cla: 'collection-area',
87		clf: 'collections-filters',
88		exc: 'exhibition-current',
89		exu: 'exhibition-upcoming',
90		exp: 'exhibition-past',
91		ext: 'exhibition-traveling',
92		exd: 'exhibition-digital',
93		evd: 'event-date',
94		evt: 'event-tax',
95		trt: 'teacher-resource-tax',
96		all: 'all-id'
97	},
98	init: () => {
99		if (pageSearch.isOnGlobalSearchPage()) {
100			window.addEventListener('DOMContentLoaded', async function () {
101				await pageSearch.loadVariables();
102				await pageSearch.addEventListenerToFilterInputs();
103				await pageSearch.loadFilterValues();
104				await pageSearch.clickOnFilterAfterPageLoaded();
105			});
106		}
107	},
108	isOnGlobalSearchPage: () => {
109		return (window.location.search.indexOf('?s=') >= 0 ? true : false);
110	},
111	loadVariables: async () => {
112		pageSearch.allInputs = document.querySelectorAll('.global-search-filter.all');
113		pageSearch.collectionInputs = document.querySelectorAll('.collections-search-filter, .at-year-to-year-input, .custom-filter-checkbox');
114		pageSearch.exhibitionInputs = document.querySelectorAll('.exhibitions-search-filter');
115		pageSearch.eventsInputs = document.querySelectorAll('.events-search-filter, .at-filters-component-events-filters-container .date-element');
116		pageSearch.teacherResourcesInput = document.querySelectorAll('.teacher-resources-search-filter');
117		pageSearch.loadFunctionCollections = {
118			all: pageSearch.loadAll,
119			collection: pageSearch.loadCollections,
120			exhibitions: pageSearch.loadExhibitions,
121			events: pageSearch.loadEvents,
122			'teacher-resources': pageSearch.loadTeacherResources
123		};
124		pageSearch.inputCollections = {
125			all: pageSearch.allInputs,
126			collection: pageSearch.collectionInputs,
127			exhibitions: pageSearch.exhibitionInputs,
128			events: pageSearch.eventsInputs,
129			'teacher-resources': pageSearch.teacherResourcesInput
130		};
131	},
132	loadFilterValues: async () => {
133		const queryStringReplaced = window.location.search.replace('?', '&');
134		let arrayParams = queryStringReplaced.split('&').slice(1);
135
136		arrayParams.forEach((item) => {
137			const [param, value] = item.split('=');
138
139			if (param == 's') {
140				pageSearch.s = value;
141				return;
142			}
143
144			if (param == 'rt') {
145				pageSearch.rt = value;
146				return;
147			}
148
149			if (['page'].includes(param)) {
150				return;
151			}
152
153			if (!isNaN(param)) {
154				pageSearch.setCheckedInputWithNumberNameOrOnlyString(param);
155				return;
156			}
157
158			if (param.indexOf('-') > 0) {
159				pageSearch.setCheckedInputWithIdInName(param);
160				return;
161			}
162
163			if (pageSearch.filterByNames[param] && pageSearch.filterByNames[param].indexOf('date') > 0) {
164				pageSearch.setValueOnDateInput({param, value});
165				return;
166			}
167
168			if (Object.keys(pageSearch.filterByNames).includes(param)) {
169				const exhibitionCheckboxName = pageSearch.filterByNames[param];
170				pageSearch.setCheckedInputWithNumberNameOrOnlyString(exhibitionCheckboxName);
171				return;
172			}
173		});
174	},
175	setCheckedInputWithNumberNameOrOnlyString: (param) => {
176		const input = document.querySelector(`.search-filter-checkbox[name="${param}"]`);
177		input.checked = true;
178		pageSearch.expandDivFilter(input);
179	},
180	setCheckedInputWithIdInName: (param) => {
181		const [preffix, id] = param.split('-');
182		const name = `${pageSearch.filterByNames[preffix]}-${id}`;
183		const input = document.querySelectorAll(`.search-filter-checkbox[name="${name}"], .custom-filter-checkbox[name="${name}"]`)[0];
184		input.checked = true;
185		pageSearch.expandDivFilter(input);
186	},
187	setValueOnDateInput: async ({param, value}) => {
188		const name = pageSearch.filterByNames[param];
189		const input = document.querySelector(`.date-element[name="${name}"]`);
190		input.value = value;
191		pageSearch.expandDivFilter(input);
192	},
193	setCheckedInputSiblings: async (inputChecked) => {
194		if (inputChecked.name.indexOf('all') == -1) {
195			return false;
196		}
197
198		const parentDiv = findParent(inputChecked, '.at-filters-component-filter-list-container');
199
200		parentDiv.childNodes.forEach((childDiv) => {
201			if (childDiv.tagName === 'DIV') {
202				if (childDiv.firstChild.name !== inputChecked.name) {
203					childDiv.firstChild.checked = inputChecked.checked;
204				}
205			}
206		});
207	},
208	uncheckInputAll: async (inputChecked) => {
209		if (
210			inputChecked.name.indexOf('all') >= 0 ||
211			inputChecked.checked ||
212			['events', 'teacher-resources'].includes(pageSearch.rt) == false
213		) {
214			return false;
215		}
216
217		const parentDiv = findParent(inputChecked, '.at-filters-component-filter-list-container');
218
219		if (parentDiv !== null) {
220			parentDiv.firstChild.firstChild.checked = false;
221		}
222	},
223	expandDivFilter: async (input) => {
224		if (input.name.indexOf('collections-filters') >= 0) {
225			return;
226		}
227
228		const element = findParent(input, '.at-filters-component-filter-by-content-container').firstChild;
229
230		if ((element.tagName !== 'BUTTON' && !pageSearch.isMobileLayout()) || element.classList.contains('expanded')) {
231			return;
232		}
233
234		if (pageSearch.rt === 'exhibitions' && pageSearch.isMobileLayout()) {
235			pageSearch.expandCollapseManuallyToExhibitions();
236		} else {
237			expandCollapseFilterCategory(element);
238		}
239
240		if (pageSearch.rt !== 'exhibitions' && pageSearch.isMobileLayout()) {
241			let mobileButton = document.querySelector('.at-filters-component-mobile-toggle-button');
242			expandCollapseMobileFilters(mobileButton);
243		}
244	},
245	expandCollapseManuallyToExhibitions: () => {
246		const mobileButton = document.querySelector('.at-filters-component-mobile-toggle-button');
247		const divFilterMobile = document.querySelector('.at-filters-component-filter-by-container');
248
249		if (!mobileButton.classList.contains('expanded')) {
250			mobileButton.classList.toggle('expanded');
251			divFilterMobile.classList.toggle('expanded');
252			mobileFiltersChangeToggleIcon('filled in');
253		}
254	},
255	isMobileLayout: () => {
256		if (window.matchMedia && window.matchMedia('(min-width: 1200px)').matches) {
257			return false;
258		}
259
260		return true;
261	},
262	addEventListenerToFilterInputs: async () => {
263		const inputTypes = ['checkbox', 'radio'];
264		const inputDates = ['event-date'];
265
266		Object.entries(pageSearch.inputCollections).forEach(entry => {
267			const [type, inputCollection] = entry;
268
269			if (!pageSearch.checkIfElementExistsOnDOM(inputCollection)) {
270				return;
271			}
272
273			const loadFunction = pageSearch.loadFunctionCollections[type];
274
275			inputCollection.forEach((inputItem) => {
276				let eventType = 'blur';
277
278				let collectionDateFields = [
279					'collection-date-created-from',
280					'collection-date-created-to',
281					'collection-date-acquired-from',
282					'collection-date-acquired-to',
283				];
284
285				if (
286					inputTypes.includes(inputItem.type) ||
287					inputDates.includes(inputItem.name)
288				) {
289					eventType = 'change';
290				}
291
292				if (collectionDateFields.indexOf(inputItem.name) >= 0) {
293					eventType = 'collectiondatepicker';
294				}
295
296				inputItem.addEventListener(eventType, async (e) => {
297					await pageSearch.setCheckedInputSiblings(inputItem);
298					await pageSearch.uncheckInputAll(inputItem);
299
300					const loadingDiv = document.querySelectorAll('#page .loading');
301					if (pageSearch.checkIfElementExistsOnDOM(loadingDiv)) {
302						e.preventDefault();
303						return;
304					}
305
306					if (!pageSearch.checkIfFilterChangeIsInTheSamePage(inputItem)) {
307						await pageSearch.resetPagination(type);
308					}
309					await loadFunction();
310				});
311			});
312		});
313	},
314	clickOnFilterAfterPageLoaded: async () => {
315		const radioInputActive = document.querySelector('.global-search-filter[type="radio"].active');
316
317		if (radioInputActive) {
318			radioInputActive.click();
319		}
320	},
321	checkIfFilterChangeIsInTheSamePage: (input) => {
322		if (input.type === 'checkbox' && globalSearchUrlParams.get('page') > 1) {
323			return false;
324		}
325		return window.location.search.indexOf(input.value) > 0 ? true : false;
326	},
327	checkIfElementExistsOnDOM: (element) => {
328		if (element === null) {
329			return false;
330		}
331
332		return element.length;
333	},
334	resetPagination: async (type) => {
335		if (type == 'collection') {
336			type = 'collections';
337		}
338		pageSearch.rt = type;
339		globalSearchUrlParams.delete('page');
340		globalPage = 1;
341
342		const newParams = pageSearch.mountBaseQueryString(type);
343		pageSearch.updateURL('reset-pagination', newParams);
344	},
345	updateURL: (name, url) => {
346		window.history.pushState(name, '', url);
347	},
348	updateURLWithFilterValues: (bodyData, type) => {
349		const metaFields = bodyData?.metaFields ? Object.entries(bodyData?.metaFields) : [];
350		const taxFields = bodyData?.taxFields ? Object.entries(bodyData?.taxFields) : [];
351		let newParams = pageSearch.mountBaseQueryString(type);
352
353		metaFields.forEach(([field, value]) => {
354			newParams += pageSearch.mountParamsToURL(field, value);
355		});
356		taxFields.forEach(([field, value]) => {
357			newParams += pageSearch.mountParamsToURL(field, value);
358		});
359
360		if (globalSearchUrlParams.get('page')) {
361			newParams += `&page=${globalSearchUrlParams.get('page')}`;
362		}
363		pageSearch.updateURL('new-filter' + newParams, newParams);
364	},
365	updatePageTitle (title) {
366		document.title = title;
367	},
368	updateContent (html) {
369		pageSearch.searchOutput.innerHTML = html;
370	},
371	updateResultCounter: (count) => {
372		const resultLabel = document.querySelector('#filter-result-label');
373		const counterResult = document.querySelector('#filter-result-counter');
374		const limitResultDisplayText = 10000;
375		let label = 'Result' + (count > 1 ? 's' : '');
376
377		count = count >= limitResultDisplayText ?
378			limitResultDisplayText.toLocaleString('en-US') + '+' :
379			parseInt(count).toLocaleString('en-US');
380		counterResult.innerHTML = count;
381		resultLabel.innerHTML = label;
382	},
383	updatePaginationContent: async (postsInfo) => {
384		const parsedPostsInfo = isJsonString(postsInfo) ? JSON.parse(postsInfo) : [];
385
386		let pagination = parsedPostsInfo['pagination'] ?? '';
387
388		paginationOutput.innerHTML = pagination.replace(/\\/g, '').replace(/u2026/g, '…').slice(1, -1);
389
390		removeLoadingBlock();
391	},
392	reloadPageBasedOnRadioActive: async () => {
393		const radioInputActive = document.querySelector('.global-search-filter[type="radio"]:checked');
394		const loadFunction = pageSearch.loadFunctionCollections[radioInputActive.value];
395		await loadFunction();
396	},
397	loadAll: async () => {
398		bodyData = pageSearch.mountBodyData([], 'collection');
399
400		delete bodyData['queryType'];
401		pageSearch.updateURLWithFilterValues(bodyData, 'all');
402		addLoading(document.querySelector('#page'), true);
403
404		const postsInfo = await pageSearch.fetchData(bodyData, globalPage);
405
406		await pageSearch.mountExhibitionListComponent(postsInfo);
407		await pageSearch.updatePaginationContent(postsInfo);
408	},
409	loadCollections: async () => {
410		const checkedCollectionInputs = document.querySelectorAll('.collections-search-filter:checked, .at-year-to-year-input, .custom-filter-checkbox:checked');
411
412		bodyData = pageSearch.mountBodyData(checkedCollectionInputs, 'collection');
413		pageSearch.updateURLWithFilterValues(bodyData, 'collections');
414		addLoading(document.querySelector('#page'), true);
415
416		const postsInfo = await pageSearch.fetchData(bodyData, globalPage);
417
418		await pageSearch.mountDynamicGridComponent(postsInfo);
419		await pageSearch.updatePaginationContent(postsInfo);
420	},
421	loadExhibitions: async () => {
422		const checkedExhibitionFields = document.querySelectorAll('.exhibitions-search-filter:checked');
423		bodyData = pageSearch.mountBodyData(checkedExhibitionFields, 'exhibition');
424
425		pageSearch.updateURLWithFilterValues(bodyData, 'exhibitions');
426		addLoading(document.querySelector('#page'), true);
427
428		const postsInfo = await pageSearch.fetchData(bodyData, globalPage);
429
430		await pageSearch.mountExhibitionListComponent(postsInfo);
431		await pageSearch.updatePaginationContent(postsInfo);
432	},
433	loadEvents: async () => {
434		const checkedEventFields = document.querySelectorAll('.events-search-filter:checked');
435		const filledEventDateFields = document.querySelectorAll('.at-filters-component-events-filters-container .date-element');
436
437		bodyData = pageSearch.mountBodyData(checkedEventFields, 'event');
438
439		if (filledEventDateFields) {
440			filledEventDateFields.forEach((field) => {
441				if (field.value.length > 0) {
442					if (!bodyData['metaFields']) {
443						bodyData['metaFields'] = {};
444					}
445
446					bodyData['metaFields'][field.name] = field.value;
447				}
448			});
449		}
450		pageSearch.updateURLWithFilterValues(bodyData, 'events');
451		addLoading(document.querySelector('#page'), true);
452
453		const postsInfo = await pageSearch.fetchData(bodyData, globalPage);
454
455		await pageSearch.mountExhibitionListComponent(postsInfo);
456		await pageSearch.updatePaginationContent(postsInfo);
457	},
458	loadTeacherResources: async () => {
459		const checkedEventFields = document.querySelectorAll('.teacher-resources-search-filter:checked');
460
461		bodyData = pageSearch.mountBodyData(checkedEventFields, 'teacher-resources');
462		pageSearch.updateURLWithFilterValues(bodyData, 'teacher-resources');
463		addLoading(document.querySelector('#page'), true);
464
465		const postsInfo = await pageSearch.fetchData(bodyData, globalPage);
466
467		await pageSearch.mountExhibitionListComponent(postsInfo);
468		await pageSearch.updatePaginationContent(postsInfo);
469	},
470	removeUnnecessaryKeys: async (fields) => {
471		if (
472			['all'].includes(pageSearch.rt) ||
473			!fields.hasOwnProperty('metaFields')
474		) {
475			return fields;
476		}
477
478		const metaFields = Object.entries(fields.metaFields);
479
480		metaFields.forEach(([field, value]) => {
481			if (field.indexOf('all') >= 0) {
482				delete fields.metaFields[field];
483			}
484		});
485
486		return fields;
487	},
488	fetchData: async (fields, page) => {
489		const searchFields = await pageSearch.removeUnnecessaryKeys(fields);
490		const searchContent = await fetchSearchResults(searchFields, page);
491
492		return searchContent;
493	},
494	mountBodyData: (elements, type) => {
495		const searchReturn = {};
496		const searchQuery = document.querySelector('input[type="search"]').value;
497		pageSearch.s = searchQuery;
498
499		if (searchQuery && searchQuery.length > 0) {
500			searchReturn['s'] = searchQuery;
501		}
502
503		if (type === 'all') {
504			return searchReturn;
505		}
506
507		type = type.replace('events', 'event');
508		type = type.replace('exhibitions', 'exhibition');
509		type = type.replace('teacher-resources', 'teacher_resource');
510		searchReturn['queryType'] = type;
511
512		if (elements) {
513			searchReturn['metaFields'] = {};
514			searchReturn['taxFields'] = {};
515
516			elements.forEach((field) => {
517				if (!field.value) {
518					return;
519				}
520
521				let fieldValue = field.value;
522
523				if (
524					field.name.includes('obj-type-') ||
525					field.name.includes('collection-area-') ||
526					field.name.includes('event-tax-') ||
527					field.name.includes('teacher-resource-tax-')
528				) {
529					fieldValue = field.name.replace(/obj-type-|collection-area-|collection-area-|event-tax-|teacher-resource-tax-/g, '');
530				}
531
532				if (field.name.includes('tax')) {
533					searchReturn['taxFields'][field.name] = fieldValue;
534				} else {
535					searchReturn['metaFields'][field.name] = fieldValue;
536				}
537			});
538		}
539
540		return searchReturn;
541	},
542	mountBaseQueryString: (type) => {
543		return `?s=${pageSearch.s}&rt=${type}`;
544	},
545	mountParamsToURL: (field, value) => {
546		let params = '';
547		const filterByNames = Object.entries(pageSearch.filterByNames);
548
549		if (!isNaN(field)) {
550			params = `&${field}=${value}`;
551		}
552
553		filterByNames.forEach(([param, name]) => {
554
555			if (field.indexOf(name) == -1) {
556				return;
557			}
558
559			if (name.indexOf('date') >= 0) {
560				params = `&${param}=${value}`;
561				return;
562			}
563
564			const arrayName = field.split('-');
565			if (arrayName.length >= 3) {
566				let lastIndex = arrayName.length - 1;
567				params = `&${param}-${arrayName[lastIndex]}=${value}`;
568				return;
569			}
570
571			if (isNaN(value)) {
572				params = `&${param}=${value}`;
573			}
574		})
575
576		return params;
577	},
578	mountDynamicGridComponent: async (postsInfo) => {
579		const parsedPostsInfo = isJsonString(postsInfo) ? JSON.parse(postsInfo) : [];
580
581		if (parsedPostsInfo) {
582			const postFields = (parsedPostsInfo['posts']);
583			const items = [];
584
585			if (postFields) {
586				postFields.forEach((postInfo) => {
587					items.push({
588						'image': postInfo['thumbnail'] ?? '',
589						'imageAltText': postInfo['custom-fields']['altText'] ?? postInfo['title'],
590						'title': postInfo['title'] ?? '',
591						'description': postInfo['custom-fields']['event_short_description'] ?? postInfo['description'],
592						'link': postInfo['link'] ?? '',
593						'hasImage': postInfo['custom-fields']['hasImage'] ?? '0',
594					});
595				});
596
597				const htmlOutput = await fetchTemplatePart('dynamicGrid', {items});
598
599				pageSearch.updateContent(htmlOutput);
600			}
601		}
602
603		if (!parsedPostsInfo || parsedPostsInfo['total-posts'] <= 0) {
604			pageSearch.updateContent(notFoundHTML);
605		}
606
607		pageSearch.updateResultCounter(parsedPostsInfo['total-posts']);
608
609		gridSort();
610	},
611	mountExhibitionListComponent: async (postsInfo) => {
612		const parsedPostsInfo = isJsonString(postsInfo) ? JSON.parse(postsInfo) : [];
613
614		if (parsedPostsInfo) {
615			const postFields = (parsedPostsInfo['posts']);
616			const fields = [];
617
618			if (postFields) {
619				postFields.forEach((postInfo) => {
620					let label = 'View';
621					let subtitle = '';
622
623					switch (postInfo['post-type']) {
624						case 'collection':
625							label = label + ' Collection Object';
626							subtitle = 'Collection Object';
627							break;
628						case 'collection_highlight':
629							label = label + ' Collection Highlight';
630							subtitle = 'Collection Highlight';
631							break;
632						case 'event':
633							label = label + ' Event';
634							subtitle = 'Event';
635							break;
636						case 'exhibition':
637							label = label + ' Exhibition';
638							subtitle = 'Exhibition';
639							break;
640						case 'page':
641							label = label + ' Page';
642							subtitle = 'Page';
643							break;
644						case 'person':
645							label = label + ' Person';
646							subtitle = 'Person';
647							break;
648						case 'press_release':
649							label = label + ' Press Release';
650							subtitle = 'Press Releases';
651							break;
652						case 'teacher_resource':
653							label = label + ' Teacher Resource';
654							subtitle = 'Teacher Resources';
655							break;
656					}
657
658					fields.push({
659						'postType': postInfo['post-type'],
660						'image': {
661							'img_src': postInfo['thumbnail'] ?? '',
662							'img_alt': postInfo['custom-fields']['altText'] ?? postInfo['title'],
663						},
664						'title': postInfo['title'] ?? '',
665						'subtitle': subtitle,
666						'date': (postInfo['custom-fields']['date_override'] != '' && postInfo['custom-fields']['date_override'] != null) ? postInfo['custom-fields']['date_override'] : postInfo['formatted-date'],
667						'description': postInfo['custom-fields']['event_short_description'] ?? postInfo['description'],
668						'link': {
669							'href': postInfo['link'] ?? '',
670							'label': label.replace('_', ' ')
671						},
672						'sold_out': postInfo['sold-out']
673					});
674				});
675
676				const htmlOutput = await fetchTemplatePart('searchResults', fields);
677
678				pageSearch.updateContent(htmlOutput);
679			}
680		}
681
682		if (!parsedPostsInfo || parsedPostsInfo['total-posts'] <= 0) {
683			pageSearch.updateContent(notFoundHTML);
684		}
685
686		pageSearch.updateResultCounter(parsedPostsInfo['total-posts']);
687	},
688	scrollToResults: async () => {
689		const resultsContainer = document.querySelector('.at-filters-component-results-box');
690
691		await scrollToElement(resultsContainer);
692	}
693}
694
695pageSearch.init();
696
697async function paginateGlobalSearch (event, element, componentType) {
698	event.preventDefault();
699
700	await pageSearch.scrollToResults();
701
702	addLoading(document.querySelector('#page'), true);
703
704	const bodyData = getFormValues();
705
706	const newPage = element.getAttribute('data-page') ?? 1;
707	const postsInfo = await pageSearch.fetchData(bodyData, newPage);
708
709	if (componentType == 'collection') {
710		await pageSearch.mountDynamicGridComponent(postsInfo);
711	} else {
712		await pageSearch.mountExhibitionListComponent(postsInfo);
713	}
714
715	await pageSearch.updatePaginationContent(postsInfo);
716
717	const resultType = pageSearch.rt ? pageSearch.rt : 'all';
718
719	globalSearchUrlParams.set('page', newPage);
720	pageSearch.updateURLWithFilterValues(bodyData, resultType);
721}
722
723function getFormValues () {
724	const radioInputActive = document.querySelector('.global-search-filter[type="radio"]:checked');
725	const inputCollectionsActive = {
726		'collection': document.querySelectorAll('.collections-search-filter:checked, .at-year-to-year-input, .custom-filter-checkbox:checked'),
727		'exhibitions': document.querySelectorAll('.exhibitions-search-filter:checked'),
728		'events': document.querySelectorAll('.events-search-filter:checked'),
729		'teacher-resources': document.querySelectorAll('.teacher-resources-search-filter:checked')
730	};
731
732	let bodyData = pageSearch.mountBodyData(inputCollectionsActive[radioInputActive.value], radioInputActive.value);
733	return bodyData;
734}
735
736async function submitGlobalSearchForm (event) {
737	event.preventDefault();
738
739	const inputS = document.querySelector('#at-search-field');
740	inputS.blur();
741
742	const loadingDiv = document.querySelectorAll('#page .loading');
743	if (pageSearch.checkIfElementExistsOnDOM(loadingDiv)) {
744		return false;
745	}
746
747	let searchFieldValue = event.target.querySelector('input[type="search"]').value;
748	const resultType = pageSearch.rt ? pageSearch.rt : 'all';
749	const bodyData = getFormValues();
750
751	addLoading(document.querySelector('#page'), true);
752
753	pageSearch.updateURLWithFilterValues(bodyData, resultType);
754	pageSearch.updatePageTitle('Search Results for "' + searchFieldValue + '"');
755
756	const postsInfo = await pageSearch.fetchData(bodyData, 1);
757
758	if (resultType == 'collections') {
759		await pageSearch.mountDynamicGridComponent(postsInfo);
760	} else {
761		await pageSearch.mountExhibitionListComponent(postsInfo);
762	}
763
764	await pageSearch.updatePaginationContent(postsInfo);
765
766	document.querySelector('.at-filters-component-results-counter').focus();
767}
768
769function resetGlobalSearchField () {
770	alert('oks');
771	const bodyData = getFormValues();
772	const resultType = globalSearchUrlParams.get('rt') ?? 'all';
773
774	pageSearch.s = '';
775	searchField.value = '';
776	searchFieldUpdate(searchField);
777	pageSearch.updateURLWithFilterValues(bodyData, resultType);
778}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.