PageSourceSearch

https://high.org/wp-content/themes/icelander-child/assets/js/global-helpers/utils.js?t=1790849128&ver=1.0.0

js high.org collected 2026-10-01 10:21:38 UTC 3,283 bytes, 135 lines download raw bytes

1/**
2 * General Helpers
3 */
4
5const offsetCorrection = window.matchMedia('screen and (min-width: 1200px)').matches ? 120 : 80;
6
7// Updates Inner Content of DOM Element with HTML
8function updateInnerHTML (element, html) {
9	if (element) {
10		element.innerHTML = html;
11	}
12}
13
14// Get the desired cookie from passed name
15function getCookie (name) {
16	let value = `; ${document.cookie}`;
17	let parts = value.split(`; ${name}=`);
18
19	if (parts.length === 2) {
20		return parts.pop().split(';').shift();
21	}
22}
23
24// Injects URL into address bar
25function injectURL (name, url) {
26	window.history.pushState(name, '', url);
27}
28
29// Checks if a string is JSON
30function isJsonString (str) {
31	try {
32		JSON.parse(str);
33	} catch (e) {
34		return false;
35	}
36	return true;
37}
38
39// Verify if we're on mobile device
40function checkIsMobile () {
41	return window.matchMedia("only screen and (max-width: 760px)").matches;
42}
43
44// Add Loading
45function addLoading (element, loadingBlock = false) {
46	if (loadingBlock) {
47		const loadingBlock = '<div class="loading" style=" position: fixed; background-color: rgba(0,0,0,0.25); text-align: center; display: flex; flex-direction: row; align-items: center; justify-content: center; z-index: 1000; font-size: 31px; color: #fff; width: 100vw; height: 100%; "><img src="/wp-content/themes/icelander-child/assets/images/loader.gif" width="150px"/></div>';
48
49		element.parentElement.style.position = 'relative';
50		element.insertAdjacentHTML('afterbegin', loadingBlock);
51		return true;
52	}
53
54	element.innerHTML = '';
55
56	const loadingHTML = '<div id="global-loading" style="min-width: 100%; min-height: 250px; height: 100%; display: flex; align-items: center; justify-content: center; font-size: 24px; background-color: rgba(255, 255, 255, 0.65);"><img src="/wp-content/themes/icelander-child/assets/images/loader.gif" width="150px"/></div>';
57
58	element.style.position = 'relative';
59	element.insertAdjacentHTML('afterbegin', loadingHTML);
60}
61
62// Remove Loading on DOM element
63function removeLoadingBlock () {
64	document.querySelector('.loading').remove();
65}
66
67// Remove Loading on Global
68function removeLoading (element) {
69	const loadingElement = element.querySelector('#global-loading');
70
71	element.style.position = '';
72
73	if (loadingElement) {
74		loadingElement.remove();
75	}
76}
77
78function findParent (element, query) {
79	const maxTries = 10;
80
81	let tries = 0;
82	let currentElement = element;
83	let foundElement = null;
84
85	do {
86		if (!currentElement || !currentElement.parentElement) {
87			break;
88		}
89
90		if (currentElement.parentElement.matches(query)) {
91			foundElement = currentElement.parentElement;
92		} else {
93			currentElement = currentElement.parentElement;
94		}
95
96		tries++;
97	} while (!foundElement || tries < maxTries);
98
99	return foundElement;
100}
101
102function scrollToElement (element) {
103	return new Promise((resolve, reject) => {
104		try {
105			if (!element) {
106				reject();
107
108				window.scrollTo({
109					top: 0,
110					behavior: 'smooth'
111				});
112			}
113
114			const elementRect = element.getBoundingClientRect();
115
116			let targetPosition = elementRect.top + window.scrollY - offsetCorrection;
117
118			window.scrollTo({
119				top: targetPosition,
120				behavior: 'smooth'
121			});
122
123			setTimeout(() => {
124				resolve();
125			}, 300);
126		} catch (e) {
127			reject(e);
128
129			window.scrollTo({
130				top: 0,
131				behavior: 'smooth'
132			});
133		}
134	});
135}

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.