PageSourceSearch

https://high.org/wp-content/themes/icelander-child/assets/js/hm-scripts.js?t=1790849127&ver=1.0.0

js high.org collected 2026-10-01 10:20:58 UTC 9,785 bytes, 310 lines download raw bytes

1/**
2 * Main Functions
3 */
4
5// First loading elements
6document.addEventListener('DOMContentLoaded', function () {
7	initpopupWindows();
8	initEmergencyDialogues();
9	gridSort();
10	loadCollectionHighlights(1, collectionHighlightsPerPage);
11});
12
13const ENTER_KEY_CODE = 13;
14
15document.addEventListener('DOMContentLoaded', function () {
16	// Init tabs Component
17	const tabsElements = document.querySelectorAll('.tabs-navigation');
18
19	if (tabsElements.length) {
20		for (let tab of tabsElements) {
21			initTabs(tab);
22		}
23	}
24
25	// Init dropdown Component
26	const dropdownElements = document.querySelectorAll('.custom-select');
27
28	if (dropdownElements.length) {
29		for (let dropdown of dropdownElements) {
30			initDropdown(dropdown);
31		}
32	}
33
34	// Clears all search fields on page load to avoid text staying after reload.
35	const searchFields = document.querySelectorAll('.at-search-field:not(.keep)');
36
37	if (searchFields.length) {
38		for (let searchField of searchFields) {
39			searchField.value = '';
40		}
41	}
42
43	const filterElementsList = document.getElementsByClassName('at-filters-component-filter-by-content-container');
44
45	if (filterElementsList.length) {
46		// Adds listener to checkboxes to update mobile toggle icon if any are ticked
47		if (window.matchMedia('(max-width: 991px)').matches) {
48			const filterCheckboxes = document.querySelectorAll('.at-filters-component-filter-by-container input[type="checkbox"]');
49
50			for (i = 0; i < filterCheckboxes.length; i++) {
51				filterCheckboxes[i].addEventListener('change', function (event) {
52					if (areFiltersApplied()) {
53						mobileFiltersChangeToggleIcon('filled in');
54					} else {
55						mobileFiltersChangeToggleIcon('expanded');
56					}
57				});
58			}
59		}
60
61		// Hides excess filters in "Filter By" elements.
62		for (let i = 0; i < filterElementsList.length; i++) {
63			let filterElementInputList = filterElementsList[i].querySelectorAll('div');
64
65			// By default, only 9 filters should be shown
66			if (filterElementInputList.length && filterElementInputList.length > 9) {
67				for (let j = 10; j < filterElementInputList.length; j++) {
68					filterElementInputList[j].classList.toggle('hidden');
69				}
70
71				let filterElementShowAllButton = filterElementsList[i].querySelector('.at-filters-component-show-all-button');
72				filterElementShowAllButton.classList.toggle('visible');
73			}
74		}
75	}
76
77	const closedDialogs = getCookie('closedDialogues');
78	const closedDialogsList = closedDialogs ? closedDialogs.split('%2C') : [];
79	const dialogWrappers = document.getElementsByClassName('dialog-wrapper');
80	for (let i = 0; i < dialogWrappers.length; i++) {
81		const dialogWrapper = dialogWrappers[i];
82		const dialogId = dialogWrapper.getAttribute('data-id');
83		if (closedDialogsList.indexOf(dialogId) === -1) {
84			dialogWrapper.classList.remove('dialog-wrapper-hidden');
85		}
86	}
87
88
89	const closedPopups = getCookie('closedPopups');
90	const closedPopupList = closedPopups ? closedPopups.split('%2C') : [];
91	const popupWrappers = document.getElementsByClassName('ir-pop-up-wrapper');
92	const popupBackground = document.getElementsByClassName('ir-popup-background')[0];
93	const popimage = document.getElementsByClassName('image')[0];
94	for (let i = 0; i < popupWrappers.length; i++) {
95		const popupWrapper = popupWrappers[i];
96		const popupId = popupWrapper.getAttribute('data-id');
97		if (closedPopupList.indexOf(popupId) === -1) {
98			popupWrapper.classList.remove('ir-pop-up-wrapper-hidden');
99			popupBackground.classList.remove('ir-pop-up-wrapper-hidden');
100			popimage.classList.remove('ir-pop-up-wrapper-hidden');
101		}
102	}
103
104	logout();
105});
106
107// Listen to the screen resizing
108document.addEventListener('resize', function () {
109	const filterElementsList = document.getElementsByClassName('at-filters-component-filter-by-content-container');
110
111	if (filterElementsList.length) {
112		const mobileFiltersToggle = document.getElementsByClassName('at-filters-component-mobile-toggle-button')[0];
113		const filtersFilterByContainer = document.getElementById('at-filters-component-filter-by-container');
114
115		// Adds listener to checkboxes to update mobile toggle icon if any are ticked
116		if (window.matchMedia('(max-width: 991px)').matches) {
117			const filterCheckboxes = document.querySelectorAll('.at-filters-component-filter-by-container input[type="checkbox"]');
118
119			for (i = 0; i < filterCheckboxes.length; i++) {
120				filterCheckboxes[i].addEventListener('click', function (event) {
121					if (areFiltersApplied()) {
122						mobileFiltersChangeToggleIcon('filled in');
123					} else {
124						mobileFiltersChangeToggleIcon('expanded');
125					}
126				});
127			}
128
129			if ((areFiltersApplied() || filtersFilterByContainer.classList.contains('expanded')) && !mobileFiltersToggle.classList.contains('expanded')) {
130				expandCollapseMobileFilters(mobileFiltersToggle);
131			}
132		}
133	}
134});
135
136// Emergency Dialogues
137function initEmergencyDialogues () {
138	const emergencyDialogues = document.querySelector('.at-emergency-dialogues');
139	const emergencyDialoguesItems = document.querySelectorAll('.at-emergency-dialogues .dialog-wrapper');
140
141	if (emergencyDialogues && emergencyDialoguesItems) {
142		emergencyDialogues.querySelector('.close-button')
143		                  .addEventListener('click', async function (event) {
144			                  event.preventDefault();
145
146			                  let dialoguesToRemove = [];
147
148			                  emergencyDialoguesItems.forEach(function (item, index) {
149				                  let dialogId = item.getAttribute('data-id') ?? 0;
150
151				                  dialoguesToRemove.push(dialogId);
152			                  });
153
154			                  emergencyDialogues.remove();
155
156			                  await fetchCloseEmergencyDialog(dialoguesToRemove);
157		                  });
158	}
159}
160
161
162// Popup Windows
163function initpopupWindows () {
164	const popupWindows = document.querySelector('.ir-pop-up');
165	const popupWindowsItems = document.querySelectorAll('.ir-pop-up .ir-pop-up-wrapper');
166	const popupBackground = document.querySelectorAll('.ir-popup-background');
167	const popupImage = document.querySelectorAll('.image');
168
169
170	if (popupWindows && popupWindowsItems) {
171		const closeButton = popupWindows.querySelector('.close-button');
172		const popupButton = popupWindows.querySelector('.popup-button');
173
174		 const closePopup = async function (event) {
175			                  event.preventDefault();
176
177												console.log('i clicked the popup x.')
178
179												let destinationUrl = null;
180
181																if (this.hasAttribute && this.hasAttribute('href')) {
182                                   destinationUrl = this.href;
183                                  }
184
185												let popupsToRemove = [];
186
187			                  popupWindowsItems.forEach(function (item, index) {
188												let popupId = item.getAttribute('data-id') ?? 0;
189
190													popupsToRemove.push(popupId);
191			                  });
192
193			                  popupWindows.remove();
194												popupBackground.forEach(el => el.remove());
195												popupImage.forEach(el => el.remove());
196
197												await fetchClosePopupWindow(popupsToRemove);
198
199												if (destinationUrl) {
200                         setTimeout(() => {
201                         console.log('Navigating now.');
202                         window.location.href = destinationUrl;
203											}, 500); // .5 second delay
204                         }
205
206		                  };
207
208											// Click event
209				    closeButton.addEventListener('click', closePopup);
210						popupButton.addEventListener('click', closePopup);
211
212				    // Escape key event
213						document.addEventListener('keydown', function (e) {
214								if (e.key === 'Escape') {
215										closePopup(e);
216				        }
217				    });
218	}
219
220}
221
222// Rescaling images
223window.addEventListener('resize', function () {
224	resizeScaled();
225});
226
227document.addEventListener('DOMContentLoaded', function () {
228	setTimeout(function () {
229		resizeScaled();
230	}, 1500); // Prevent bad connections to not seeing this
231});
232
233function resizeScaled () {
234	const retry = 5;
235	const elementsToResize = document.querySelectorAll('.image-to-scale');
236
237	let resized = false;
238	let retriesCounter = 1;
239
240	let backoffRetry = setInterval(function () {
241		if (elementsToResize.length) {
242			for (let elementToResize of elementsToResize) {
243				if (typeof elementToResize == "object") {
244					const childElement = elementToResize.children[0];
245					const elementWidth = childElement.clientWidth;
246					const scale = elementToResize.getAttribute('data-scale');
247
248					if (scale === 'full') {
249						elementToResize.style.height = '100%';
250
251						resized = true;
252					} else {
253						let elementNewHeight = calcScale(elementWidth, scale, "-");
254
255						elementToResize.style.height = elementNewHeight + "px";
256
257						resized = true;
258					}
259				}
260			}
261		}
262
263		retriesCounter++;
264
265		if (retriesCounter > retry || resized) {
266			clearInterval(backoffRetry);
267		}
268
269	}, 1000 + (retriesCounter * 1000)); // increasing time space between retries
270}
271
272function calcScale (initialWidth, proportion, separator) {
273	let [width, height] = proportion.split(separator);
274
275	return (initialWidth * height) / width;
276}
277
278function logout () {
279	const logoutContainer = document.querySelector('#logoutContainer');
280
281	if (logoutContainer) {
282		const counter = logoutContainer.querySelector('#counter');
283		const returnUrl = logoutContainer.getAttribute('data-return') ?? '';
284
285		let init = 3;
286		let step = 0;
287		let counterInterval = setInterval(() => {
288			step = init;
289
290			if (counter) {
291				counter.innerHTML = step;
292			}
293
294			init--;
295
296			if (init <= 0) {
297				clearInterval(counterInterval);
298
299				window.location.href = returnUrl.length ? returnUrl : 'https://high.org/';
300			}
301		}, 1000);
302	}
303}
304
305/* TNEW LOGOUT */
306document.addEventListener('DOMContentLoaded', async function () {
307	if (window.location.href == 'https://my.high.org/account/logout') {
308		window.location.href = "https://high.org/logout/?returnUrl=https://high.org/tickets/"
309	}
310});

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.