PageSourceSearch

https://dendanskemaritimefond.dk/wp-content/plugins/stom-advanced-…/assets/js/stom-ais.js?ver=6.7.9

js dendanskemaritimefond.dk collected 2026-10-02 06:05:26 UTC 31,821 bytes, 911 lines download raw bytes

1(function($) {
2	
3	/**
4	 * Define Basic Settings
5	 */
6	let stom_ais_search_offset = 0;
7	let InfScrollTriggered = false;
8	let debugEnabled = false;
9	let stom_instantsearch_value = '';
10
11	/**
12	 * Functions Below - "stom_ais_search" excluded, it resides at the bottom of the script
13	 */
14
15	
16	function throttleEvent(fn, delay) {
17		let time = Date.now();
18	   
19		return () => {
20			if((time + delay - Date.now()) <= 0) {
21				fn();
22				time = Date.now();
23			}
24		}
25	}
26
27	/**
28	 * jQuery function to determine if element is inside the browsers view
29	 * Used by Infinity Scroll
30	 */
31	jQuery.fn.StomAis_IsInViewport = function() {
32		if (!$(this).is(':visible'))
33			return false;
34
35	    var elementTop = $(this).offset().top;
36	    var elementBottom = elementTop + $(this).outerHeight();
37	    var viewportTop = $(window).scrollTop();
38	    var viewportBottom = viewportTop + $(window).height();
39	    return elementBottom > viewportTop && elementTop < viewportBottom;
40	};
41
42	/**
43	 * Change browser url to search page with search string & filters
44	 */
45	function setSearchPageUrlParam(searchValue) {
46		searchValue = typeof searchValue === 'undefined' ? $('#stom-ais-input-wrapper__form__input').val() : searchValue;
47		var newHistoryUrl = '';
48
49		if ('' == searchValue) {
50			if ($('#stom-ais-input-wrapper__form').data('stom-ais-current-url'))
51				newHistoryUrl = $('#stom-ais-input-wrapper__form').data('stom-ais-current-url');
52		} else {
53			var customSearchPageUrl = $('#stom-ais-input-wrapper__form').attr('data-custom-action');
54			if (customSearchPageUrl) {
55				if (!$('#stom-ais-input-wrapper__form').data('stom-ais-current-url'))
56					$('#stom-ais-input-wrapper__form').data('stom-ais-current-url', window.location.href);
57
58				if (searchValue.includes('/')) {
59					searchValue = searchValue.replaceAll('/', '~~~');
60				}
61
62				var newUrl = customSearchPageUrl + encodeURIComponent(searchValue) + '/';
63
64				if (newUrl != window.location.href) {
65					newHistoryUrl = newUrl;
66				}
67
68
69				var activeFilters = {},
70					urlFilters = '';
71
72				$('.stom-ais-filters__filter__choice__checkbox-hidden:checked').each(function() {
73					var $filterChoice = $(this).closest('.stom-ais-filters__filter__choice');
74
75					activeFilters[$(this).attr('id')] = $('.stom-ais-filters__filter__choice__title', $filterChoice).text();
76				});
77
78				if (Object.keys(activeFilters).length) {
79					for (const key in activeFilters) {
80						if (activeFilters.hasOwnProperty(key)) {
81							var filterId = key.replace('filter_', '');
82							filterId = filterId.replace('_choice_', '.');
83
84							var filterName = encodeURIComponent(activeFilters[key]);
85							filterName = filterName.replaceAll('%20', '+');
86
87							var filterUrlParam = filterName + '_' + filterId;
88
89							urlFilters += filterUrlParam + '/';
90						}
91					}
92				}
93
94				if (urlFilters) {
95					urlFilters = 'filters/' + urlFilters;
96					newHistoryUrl += urlFilters;
97				}
98			}
99		}
100
101
102		window.history.pushState({}, '', newHistoryUrl);
103	}
104
105
106	function getScrollbarWidth() {
107		var outer = document.createElement("div");
108		outer.style.visibility = "hidden";
109		outer.style.width = "100px";
110		outer.style.msOverflowStyle = "scrollbar"; // needed for WinJS apps
111
112		document.body.appendChild(outer);
113
114		var widthNoScroll = outer.offsetWidth;
115		// force scrollbars
116		outer.style.overflow = "scroll";
117
118		// add innerdiv
119		var inner = document.createElement("div");
120		inner.style.width = "100%";
121		outer.appendChild(inner);
122
123		var widthWithScroll = inner.offsetWidth;
124
125		// remove divs
126		outer.parentNode.removeChild(outer);
127
128		return widthNoScroll - widthWithScroll;
129	}
130
131
132	function applyBodyOverflow() {
133		$('html, body').css('overflow', 'hidden');
134		$('body').css('padding-right', getScrollbarWidth());
135	}
136
137
138	function removeBodyOverflow() {
139		$('html, body').css('overflow', '');
140		$('body').css('padding-right', '');
141	}
142
143
144	function getBrowserCookie(cname) {
145		let name = cname + "=";
146		let decodedCookie = decodeURIComponent(document.cookie);
147		let ca = decodedCookie.split(';');
148
149		for (let i = 0; i <ca.length; i++) {
150			let c = ca[i];
151			while (c.charAt(0) == ' ') {
152				c = c.substring(1);
153			}
154
155			if (c.indexOf(name) == 0) {
156				return c.substring(name.length, c.length);
157			}
158		}
159
160		return "";
161	}
162
163	/**
164	 * Function to handle search wrapper/container initialization
165	 */
166	function maybeInitializeSearchContainer() {
167		// Initialize Search Container
168		let $container = $('#stom-ais-wrapper.ais-rendered');
169		if ($container.length == 0) {
170			if(debugEnabled)console.log('STOM AIS:','No rendered container exists');
171
172			$container = $('#stom-ais-wrapper');
173			if ($container.length == 0) {
174				if(debugEnabled)console.log('STOM AIS:','Container does not exist. Appending to body.');
175
176				$('body').append('<div id="stom-ais-wrapper" style="display:none;"></div>');
177				window.stomAisSettings.isSearchInline = false;
178			}
179
180			$container = $('#stom-ais-wrapper');
181
182			if (typeof stom_instantsearch_mustache.search_container === 'undefined') {
183				console.error('STOM AIS:','Cannot locate container template.');
184				return false;
185			}
186
187			if(debugEnabled)console.log('STOM AIS:','Rendering container template.');
188
189			let results_view = stom_instantsearch.search.results_view;
190
191			let templates_search_items = {};
192			$.each(stom_instantsearch_mustache.search,function(index){
193				let template = stom_instantsearch_mustache.search[index];
194				let args = {};
195				if(index == 'filters'){
196					args.filters = stom_instantsearch.filters;
197				}
198				// console.log('Rendering template',index,args);
199				template = Mustache.render(template, args);
200				templates_search_items[index] = template;
201			});
202
203			let search_container_html = Mustache.render(stom_instantsearch_mustache.search_container, {
204				"search": templates_search_items,
205				"display_type": (window.stomAisSettings.displayTypeFromCookie ? window.stomAisSettings.displayTypeFromCookie : results_view),
206				"display_result_images": (window.stomAisSettings.displayResultImages ? 'true' : ''),
207			});
208
209			if (!search_container_html) {
210				console.error('STOM AIS:','Could not render container template.');
211				return false;
212			}
213
214			$container.replaceWith(search_container_html);
215			$container = $('#stom-ais-wrapper');
216			$container.addClass('ais-rendered');
217
218			$('#stom-ais-filters').hide();
219
220			if (window.stomAisSettings.isSearchInline) {
221				$container.show(0);
222			}
223
224			// Garbage collection
225			templates_search_items, search_container_html = null;
226		}else{
227			if(debugEnabled)console.log('STOM AIS:','Container already rendered.');
228		}
229	}
230
231
232
233	/**
234	 * GLOBAL VARIABLES
235	 */
236
237	const Mustache = window.mustache;
238
239	window.stomAisSettings = {
240		isSearchInline: true,
241		searchTriggerSelector: '.woo-search, .woo-search *, .instantsearch-trigger, .instantsearch-trigger *',
242		searchCloseSelector: '#stom-ais-close, #stom-ais-close *',
243		templatePosts: stom_instantsearch_mustache.posts, // Default Mustache.js - Fetch Template from database
244		displayTypeFromCookie: (getBrowserCookie('stom-ais-result-view') ? getBrowserCookie('stom-ais-result-view') : stom_instantsearch.search.results_view),
245		currentSearchString: '',
246		fadeSpeed: 175,
247		urlFiltersHandled: false,
248		displayResultImages: stom_instantsearch.data_show_images,
249	};
250
251
252
253	/**
254	 * EVENT LISTENERS
255	 */
256
257	$(document).ready(function() {
258		if ($('#stom-ais-wrapper').length !== 0) {
259			maybeInitializeSearchContainer();
260			stom_instantsearch_value = $('#stom-ais-input-wrapper__form__input').val();
261			stom_ais_search(stom_instantsearch_value);
262		}
263	});
264
265
266	/* Prevent "enter" from submitting form */
267	$(document).on('keydown', '#stom-ais-input-wrapper__form__input', function(e){
268		if (e.which == 13) {
269			setSearchPageUrlParam();
270			e.preventDefault();
271		}
272	});
273
274
275	/* Event handling for checkbox filters */
276	$(document).on('change', '.stom-ais-filters__filter__choice__checkbox-hidden', function(e){
277		stom_instantsearch_value = $('#stom-ais-input-wrapper__form__input').val();
278		stom_ais_search_offset = 0; // Reset offset before new search with filters
279		stom_ais_search(stom_instantsearch_value);
280		setSearchPageUrlParam();
281	});
282
283
284	/* Handle the selection of which view results are displayed with */
285	$(document).on('click', '.stom-ais-details__controls__button', function() {
286		var newValue = $(this).attr('data-list-view');
287
288		$('#stom-ais-wrapper').attr('data-display-type', newValue);
289		$('.stom-ais-details__controls__button').removeClass('active');
290		$(this).addClass('active');
291
292		var d = new Date(),
293			exdays = 30;
294		d.setTime(d.getTime() + (exdays * 24 * 60 * 60 * 1000));
295		var expires = "expires="+ d.toUTCString();
296		document.cookie = "stom-ais-result-view=" + newValue + ";" + expires + ";domain=" + stom_instantsearch.cookie_domain + ";path=" + stom_instantsearch.cookiepath + ";";
297		window.stomAisSettings.displayTypeFromCookie = newValue;
298	});
299
300
301	/* Redirect to custom search page, if it exists, on clicking the "search" button */
302	$(document).on('click', '#stom-ais-input-wrapper__form__submit', function(e) {
303		e.preventDefault();
304
305		var searchValue = $('#stom-ais-input-wrapper__form__input').val();
306		if (!searchValue)
307			return true;
308
309
310		var customSearchPageUrl = $('#stom-ais-input-wrapper__form').attr('data-custom-action');
311		if (customSearchPageUrl) {
312			// if (searchValue.includes('/')) {
313			// 	searchValue = searchValue.replaceAll('/', '~~~');
314			// }
315
316			// var newUrl = customSearchPageUrl + encodeURIComponent(searchValue) + '/';
317
318			// if (window.location.href == newUrl)
319			// 	window.location.reload();
320			// else
321			// 	window.location.href = newUrl;
322
323
324			setSearchPageUrlParam();
325			window.location.reload();
326		} else {
327			$('#stom-ais-input-wrapper__form').trigger('submit');
328		}
329	});
330
331
332	$(document).on('click', function(e){
333		var $target = $(e.target);
334
335		if (
336			$target.is(window.stomAisSettings.searchTriggerSelector)
337			|| $target.is(window.stomAisSettings.searchCloseSelector)
338		) {
339			e.preventDefault();
340			e.stopImmediatePropagation();
341
342			$('.woo-search-input').stop(true, false);
343			$('.woo-search-input').removeAttr('style');
344
345			if ($target.is(window.stomAisSettings.searchTriggerSelector)) {
346				maybeInitializeSearchContainer();
347
348				if (!window.stomAisSettings.isSearchInline && !$('#stom-ais-wrapper').is(':visible')) {
349					$('#stom-ais-wrapper').fadeIn(window.stomAisSettings.fadeSpeed);
350					applyBodyOverflow();
351				}
352
353				let $input_elm = $('#stom-ais-input-wrapper__form__input');
354				if ($input_elm.length > 0) {
355					let input_elm = $input_elm.get(0);
356					input_elm.focus();
357					input_elm.setSelectionRange(input_elm.value.length, input_elm.value.length);
358				}
359			} else {
360				if (!window.stomAisSettings.isSearchInline && $('#stom-ais-wrapper').is(':visible')) {
361					$('#stom-ais-wrapper').fadeOut(window.stomAisSettings.fadeSpeed);
362					removeBodyOverflow();
363				}
364			}
365		}
366	});
367
368	$(document).on('input', '#stom-ais-input-wrapper__form__input', function(e) {
369		stom_instantsearch_value = $(this).val();
370		stom_ais_search_offset = 0; // Reset offset before new search
371		stom_ais_search(stom_instantsearch_value);
372	});
373
374	$(document).on('click', '#stom-ais__load-more-results__button', function(e) {
375		e.preventDefault();
376		stom_instantsearch_value = $('#stom-ais-input-wrapper__form__input').val();
377		stom_ais_search(stom_instantsearch_value);
378	});
379
380	/*
381	 * Infinity Scroll Handler
382	 * Note: Native Scroll handler for element specific scrolling events
383	 */
384
385	function stom_ais_infinityscroll_event_handler(event){
386	    // if (event.target.id === 'stom-ais-results') { // or any other filtering condition        
387	    //     console.log('scrolling 2', event.target);
388	    // }else{
389	    //     console.log('scrolling 1', event.target);
390	    // }
391
392		if (InfScrollTriggered)return;
393		if (!$('#stom-ais__load-more-results__button').length){
394			console.warn('STOM AIS:','Infinity scroll could not locate target');
395			InfScrollTriggered = true;
396			window.setTimeout(function(){InfScrollTriggered = false;},3000);
397			return;
398		}
399		
400		if ($('#stom-ais__load-more-results__button').StomAis_IsInViewport()){
401			stom_ais_search_offset += parseInt(stom_instantsearch.data_limit);
402			$('#stom-ais__load-more-results__button').trigger('click');
403			InfScrollTriggered = true;
404			if(debugEnabled)console.log('STOM AIS:','Search triggered with infinity scroll');
405			// window.setTimeout(function(){InfScrollTriggered = false;},1000);
406		}else{
407			// window.setTimeout(function(){InfScrollTriggered = false;},3000);
408		}
409
410
411	}
412
413	window.addEventListener("resize", stom_ais_infinityscroll_event_handler);
414	document.addEventListener('scroll',stom_ais_infinityscroll_event_handler, true /*Capture event*/);
415
416
417	document.addEventListener('scroll', throttleEvent(stom_ais_sticky_details_handler, 20), true);
418	function stom_ais_sticky_details_handler() {
419		if (!$("#stom-ais-details .stom-ais__inner-container").length || !$("#stom-ais-details .stom-ais__inner-container").offset())
420			return true;
421
422
423		if (typeof window.stomAisSettings.stickyDetailsActive != undefined && window.stomAisSettings.stickyDetailsActive) {
424			if ($("#stom-ais-details").offset().top > window.stomAisSettings.stickyDetailsTopBreakpoint) {
425				window.stomAisSettings.stickyDetailsActive = false;
426				window.stomAisSettings.stickyDetailsTopBreakpoint = null;
427				window.stomAisSettings.stickyDetailsPlaceholderHeight = null;
428
429				stom_ais_sticky_details_deactivate();
430			}
431		} else if (typeof window.stomAisSettings.stickyDetailsActive != undefined || !window.stomAisSettings.stickyDetailsActive) {
432			if (0 > $("#stom-ais-details .stom-ais__inner-container").offset().top - $("#stom-ais-inner .stom-ais-container").offset().top) {
433				window.stomAisSettings.stickyDetailsActive = true;
434				window.stomAisSettings.stickyDetailsTopBreakpoint = $("#stom-ais-detail
434s").offset().top + 1 // buffer
435				window.stomAisSettings.stickyDetailsPlaceholderHeight = $('#stom-ais-details').height();
436
437				stom_ais_sticky_details_activate();
438			}
439		}
440	}
441
442	function stom_ais_sticky_details_activate() {
443		$('#stom-ais-details').css('min-height', window.stomAisSettings.stickyDetailsPlaceholderHeight);
444		$('#stom-ais-details').addClass('sticky');
445	}
446
447	function stom_ais_sticky_details_deactivate() {
448		$('#stom-ais-details').css('min-height', '');
449		$('#stom-ais-details').removeClass('sticky');
450	}
451
452
453	// $(window).on('scroll', function(){
454	// 	if (InfScrollTriggered) return;
455	// 	if (!$('#stom-ais__load-more-results__button').length) return;
456	// 	if ($('#stom-ais__load-more-results__button').StomAis_IsInViewport()){
457	// 		stom_ais_search_offset += parseInt(stom_instantsearch.data_limit);
458	// 		$('#stom-ais__load-more-results__button').trigger('click');
459	// 		InfScrollTriggered = true;
460	// 		if(debugEnabled)console.log('STOM AIS:','Search triggered with infinity scroll');
461	// 		// window.setTimeout(function(){InfScrollTriggered = false;},1000);
462	// 	}else{
463	// 		// window.setTimeout(function(){InfScrollTriggered = false;},3000);
464	// 	}
465	// });
466
467	/**
468	 * Main Search Function, handles all the logic for search responses
469	 */
470	function stom_ais_search(search_string){
471
472		// Handle filters from URL
473		if (!window.stomAisSettings.urlFiltersHandled) {
474			window.stomAisSettings.urlFiltersHandled = true;
475
476			var customSearchPageUrl = $('#stom-ais-input-wrapper__form').attr('data-custom-action'),
477				currentUrl = window.location.href;
478
479			if (customSearchPageUrl && currentUrl.includes(customSearchPageUrl)) {
480				var potentialSearchFilters = currentUrl.replace(customSearchPageUrl, ''),
481					filterSearchString = '/filters/';
482
483				if (potentialSearchFilters.includes(filterSearchString)) {
484					pre(potentialSearchFilters);
485					
486					unwantedUrlPart = potentialSearchFilters.substring(0, potentialSearchFilters.indexOf(filterSearchString) + filterSearchString.length);
487					potentialSearchFilters = potentialSearchFilters.replace(unwantedUrlPart, '');
488					pre(potentialSearchFilters.indexOf('?'));
489					if (-1 !== potentialSearchFilters.indexOf('?'))
490						potentialSearchFilters = potentialSearchFilters.substring(0, potentialSearchFilters.indexOf('?'));
491
492					pre(potentialSearchFilters);
493
494					if ('/' == potentialSearchFilters.charAt(potentialSearchFilters.length - 1))
495						potentialSearchFilters = potentialSearchFilters.slice(0, -1);
496
497					potentialSearchFilters = potentialSearchFilters.split('/');
498
499					if (potentialSearchFilters.length) {
500						potentialSearchFilters.forEach(function(value, index) {
501							var filterIds = value.substring(value.lastIndexOf('_') + 1, value.length),
502								filterIdSelector = 'filter_x_choice_y';
503
504							if (filterIds.length) {
505								filterIds = filterIds.split('.');
506
507								filterIdSelector = filterIdSelector.replace('x', filterIds[0]);
508								filterIdSelector = filterIdSelector.replace('y', filterIds[1]);
509
510								if ($('#' + filterIdSelector).length) {
511									$('#' + filterIdSelector).prop('checked', true);
512								}
513							}
514						});
515					}
516				}
517			}
518		}
519
520
521		if (search_string.length < 2) {
522			// $('#stom-ais-filters, #stom-ais-details').hide();
523			if (search_string.length == 0) {
524				let filters_template = Mustache.render(stom_instantsearch_mustache.search.filters, {filters: stom_instantsearch.filters});
525				$('#stom-ais-filters').html(filters_template).hide();
526				$('#stom-ais-results .stom-ais__inner-container').html('');
527				$('#stom-ais-details').html('');
528				// setSearchPageUrlParam(false);
529				console.warn('STOM AIS:','Search string is empty');
530			}else{
531				console.warn('STOM AIS:','Search string is too short');
532			}
533			return false;
534		}
535
536		if(debugEnabled)console.log('STOM AIS:','Search triggered');
537		if(debugEnabled)console.log('STOM AIS:','Search offset',stom_ais_search_offset);
538
539		window.stomAisSettings.currentSearchString = search_string;
540
541		// Active filters
542		var activeFilters = [];
543
544		// let filter_selector = '.stom-ais-filters__filter__choice__checkbox-hidden:checked';
545		let filter_selector = '.stom-ais-filters__filter__choice__checkbox-hidden';
546		if ($(filter_selector).length) {
547			$(filter_selector).each(function() {
548				var $parent = $(this).closest('.stom-ais-filters__filter__choice');
549
550				activeFilters.push({
551					'htmlId': $(this).attr('id'),
552					'type': $parent.attr('data-filter'),
553					'value': $parent.attr('data-value'),
554					'key': $parent.attr('data-key'),
555					'active': ($(this).is(':checked') ? 1 : 0),
556				});
557
558				if($(this).is(':checked')){
559					if(debugEnabled)console.log('STOM AIS:','Selected Filter', $(this).attr('id'), $(this));
560				}
561
562			});
563		}
564
565		// setSearchPageUrlParam();
566
567		// Block selecting filters that in combination don't have results, until reload finished
568		// $('.stom-ais-filters__filter__choice__checkbox-hidden').prop( "disabled", true );
569
570		// $('.stom-ais-filters__filter__choice__checkbox-hidden').addClass('triggered');
571		// $('.stom-ais-filters__filter__choices').addClass('triggered');
572
573		$.ajax({
574			type: "POST",
575			async: true,
576			url: stom_instantsearch.api_url,
577			data: {
578				'api_args': {
579					'action': 'search',
580					'query': search_string,
581					'key': stom_instantsearch.key,
582					'type': stom_instantsearch.data_type,
583					'lang': stom_instantsearch.data_lang,
584					'limit': stom_instantsearch.data_limit,
585					'offset': stom_ais_search_offset,
586					'filters': activeFilters,
587					// 'domain': stom_instantsearch.api_domain,
588					// 'exclude_prod_ids': stom_instantsearch.data.exclude_prod_ids,
589					// 'exclude_cat_ids': stom_instantsearch.data.exclude_cat_ids
590				}
591			},
592			error: function(jqXHR, textStatus, errorThrown){
593				console.error('STOM AIS:', jqXHR, textStatus, errorThrown);
594				if(InfScrollTriggered){
595					window.setTimeout(function(){InfScrollTriggered = false;},3000);
596				}
597				// $('.stom-ais-filters__filter__choice__checkbox-hidden').removeClass('triggered');
598				$('.stom-ais-filters__filter__choices').removeClass('triggered');
599			},
600			success: function(response){
601
602				if(debugEnabled)console.log('STOM AIS: Response', response);
603
604				// Prevent old results from overtaking the newest result
605				if (window.stomAisSettings.currentSearchString != search_string) {
606					console.warn('STOM AIS:','Search response drifted. This response was not the latest search !');
607					return false;
608				}
609
610				if (typeof response.posts != 'object' || typeof response.query != 'object') {
611					console.error('STOM AIS:','Search returned with an invalid response');
612					$('#stom-ais-results .stom-ais__inner-container').html('An error occurred. Please try again');
613					return false;
614				}
615
616				/*
617				let rand = function(min, max){ return Math.floor(Math.random() * (max - min + 1) + min); };
618				stom_ais_search_filters = {"groups":[{"filter_id":"filter_1","name":"Indholds Typer","type":"checkbox","is_checkbox":true,"choices":[{"choice_id":"choice_1","filter":"post_type","name":"Alle Produkter","value":"product","count":rand(0,1000),"choice_selected":true,},{"choice_id":"choice_2","filter":"post_type","name":"Alle Sider","value":"page","count":rand(0,1000),"choice_selected":false,},{"choice_id":"choice_3","filter":"post_type","name":"Alle Indlæg","value":"post","count":rand(0,1000),"choice_selected":true,},],},{"filter_id":"filter_2","name":"Uddannelser","type":"checkbox","is_checkbox":true,"choices":[{"choice_id":"choice_1","filter":"taxonomy_term","name":"Fuldtidsuddannelser","value":"41","count":rand(0,1000),},{"choice_id":"choice_2","filter":"taxonomy","name":"Uddannelser","value":"category","count":rand(0,1000),},{"choice_id":"choice_3","filter":"meta_data","name":"Har supplerende kurser","key":"_children","value":"yes","count":rand(0,1000),},],},],}
619				*/
620
621				stom_ais_search_filters = stom_instantsearch.filters;
622
623				if (typeof response.filters == 'object') {
624					stom_ais_search_filters = response.filters;
625				}else if(typeof response.filters_args == 'object'){
626					if (response.filters_args.length) {
627						response.filters_args.forEach(function(filterData, index) {
628							if(filterData.active == "1"){
629								$('#' + filterData.htmlId).prop( "checked", true );
630							}
631						});
632					}
633				}
634
635				// @TODO: Indsæt filters template rendering via api responses
636				let search_filters_html = Mustache.render(stom_instantsearch_mustache.search.filters, {
637					"filters": stom_ais_search_filters,
638    			});
639				$('#stom-ais-filters').replaceWith(search_filters_html);
640
641				// $('.stom-ais-filters__filter__choice__checkbox-hidden').each(function() {
642				// 	$(this).removeAttr('checked');
643				// 	$(this).removeAttr('disabled');
644				// });
645
646				// if (typeof response.filters_args == 'object') {
647				// 	if (response.filters_args.length) {
648				// 		// console.log('Here?', response.filters_args);
649				// 		response.filters_args.forEach(function(filterData, index) {
650				// 			if(filterData.active == "1"){
651				// 				$('#' + filterData.htmlId).prop( "checked", true );
652				// 			}
653				// 		});
654				// 	}
655				// }
656
657				if (activeFilters.length) {
658					activeFilters.forEach(function(filterData, index) {
659						if(filterData.active == 1){
660							$('#' + filterData.htmlId).prop( "checked", true );
661						}else{
662							// $('#' + filterData.htmlId).prop( "disabled", true );
663						}
664					});
665				}
666
667				// ###################
668				// Lokal ændring af filter counts ud fra response data
669				let filters_count = [];
670				if (typeof response.filters_count == 'object') {
671					filters_count = response.filters_count;
672				}
673				if (filters_count.length !== 'undefined' && filters_count.length !== 0) {
674					$.each(filters_count,function(id,value){
675						$('#'+id).parent().find('.stom-ais-filters__filter__choice__count').text('('+value+')');
676						// console.log(id,value);
677						if(value == 0){
678							$('#' + id).prop( "disabled", true );
679						}else{
680							$('#' + id).prop( "disabled", false );
681						}
682					});
683				} else {
684					$('.stom-ais-filters__filter__choice__checkbox-hidden:not(:checked)').each(function() {
685						$(this).prop( "disabled", true );
686					});
687				}
688				// ###################
689
690				let num_results = response.query.count_results + response.query.offset;
691				if(num_results > response.query.count_posts_queried)num_results = response.query.count_posts_queried;
692				// if(num_results == 0)num_results += response.query.offset;
693
694				let search_details_html = Mustache.render(stom_instantsearch_mustache.search.details, {
695					"query": {
696						'string': search_string,
697						'results': response.query.count_results,
698						// 'results_returned': response.query.count_results,
699						// 'results_returned': response.query.count_results+response.query.offset,
700						'results_returned': num_results,
701						'results_total': response.query.count_posts_queried, // Antal resultater for søgningen
702						'count': response.query.count_posts, // Total antal resultater tilgængelige
703						'total_count': response.query.count_posts, // Total antal resultater tilgængelige
704						'exec_time': response.query.execution_time
705					},
706					"result-view-list": ('list' == window.stomAisSettings.displayTypeFromCookie ? ' active' : ''),
707					"result-view-grid": ('grid' == window.stomAisSettings.displayTypeFromCookie ? ' active' : ''),
708				});
709				$('#stom-ais-details').replaceWith(search_details_html);
710
711				let posts_view_order = [
712					// 'product',
713					// 'post',
714					// 'page'
715				];
716
717				let types = Object.keys(response.posts);
718				if(types.length > 0){
719					$.each(types,function(i,type){
720						if(posts_view_order.includes(type))return true;
721						posts_view_order.push(type);
722					});
723				}
724
725				if(response.query.offset != 0){
726					if(debugEnabled)console.log('STOM AIS:','Search with offset. Append to existing result list');
727				}else{
728					if(debugEnabled)console.log('STOM AIS:','Search with no offset. Resetting result list');
729					$('#stom-ais-results .stom-ais__inner-container').html('');
730				}
731
732				let posts_sorted_score = [];
733				$.each(posts_view_order, function(i,type) {
734					if (typeof response.posts[type] != 'object')
735						return true;
736
737
738					let template = window.stomAisSettings.templatePosts;
739					if(typeof stom_instantsearch_mustache['posts_'+type] != 'undefined'){
740						if(debugEnabled)console.log('STOM AIS:','Selecting template for "',type,'"');
741						template = stom_instantsearch_mustache['posts_'+type];
742					}
743
744					if(response.posts[type].length == 0){
745						if(debugEnabled)console.log('STOM AIS:','Search did not return any results for "', type,'"');
746					}else{
747						$.each(response.posts[type],function(i,post){
748							post.post_content = $.truncate(post.post_content, {
749								length: stom_instantsearch.search.truncate.length,
750								ellipsis: stom_instantsearch.search.truncate.ellipsis,
751								words: stom_instantsearch.search.truncate.words
752							});
753
754							posts_sorted_score.push(post);
755						});
756					}
757				});
758
759				
760				posts_sorted_score.sort(function (a, b) {
761					return ( a.score > b.score ? -1 : ( a.score < b.score ? 1 : 0 ) );
762				});
763
764				$.each(posts_sorted_score, function(i, post) {
765					let type = post.post_type;
766
767					// post.post_type = post.post_type == 'post' ? 'Indlæg' : 'Side';
768
769					let template = window.stomAisSettings.templatePosts;
770					if (typeof stom_instantsearch_mustache['posts_'+type] != 'undefined') {
771						if(debugEnabled)console.log('STOM AIS:','Selecting template for "',type,'"');
772						template = stom_instantsearch_mustache['posts_'+type];
773					}
774
775					let post_html = Mustache.render(template, {
776						"item": post,
777						"display_images": (window.stomAisSettings.displayResultImages ? 'true' : '')
778					});
779					
780					$('#stom-ais-results .stom-ais__inner-container').append($(post_html).hide().fadeIn(0));
781				});
782
783				if(InfScrollTriggered && num_results < response.query.count_posts_queried){
784					window.setTimeout(function(){
785						InfScrollTriggered = false;
786						stom_ais_infinityscroll_event_handler();
787					},50);
788				}
789
790
791				if (typeof window.stomAisSettings.stickyDetailsActive != undefined && window.stomAisSettings.stickyDetailsActive) {
792					stom_ais_sticky_details_activate();
793				}
794
795
796				if (num_results == response.query.count_posts_queried) {
797					$('#stom-ais__load-more-results__button').hide();
798				} else {
799					$('#stom-ais__load-more-results__button').show();
800				}
801			}
802		});
803	}
804})(jQuery);
805
806
807
808/**
809 * Temporary text truncate function
810 */
811(function($) {
812
813	// Matches trailing non-space characters.
814	var chop = /(\s*\S+|\s)$/;
815
816	// Matches the first word in the string.
817	var start = /^(\S*)/;
818
819	// Return a truncated html string.  Delegates to $.fn.truncate.
820	$.truncate = function (html, options) {
821		return $('<div></div>').append(html).truncate(options).html();
822	};
823
824	// Truncate the contents of an element in place.
825	$.fn.truncate = function (options) {
826		if ($.isNumeric(options)) options = { length: options };
827		var o = $.extend({}, $.truncate.defaults, options);
828
829		return this.each(function () {
830			var self = $(this);
831
832			if (o.noBreaks) self.find('br').replaceWith(' ');
833
834			var text = self.text();
835			var excess = text.length - o.length;
836
837			if (o.stripTags) self.text(text);
838
839			// Chop off any partial words if appropriate.
840			if (o.words && excess > 0) {
841				var truncated = text.slice(0, o.length).replace(chop, '').length;
842
843				if (o.keepFirstWord && truncated === 0) {
844					excess = text.length - start.exec(text)[0].length - 1;
845				} else {
846					excess = text.length - truncated - 1;
847				}
848			}
849
850			if (excess < 0 || !excess && !o.truncated) return;
851
852			// Iterate over each child node in reverse, removing excess text.
853			$.each(self.contents().get().reverse(), function (i, el) {
854				var $el = $(el);
855				var text = $el.text();
856				var length = text.length;
857
858				// If the text is longer than the excess, remove the node and continue.
859				if (length <= excess) {
860					o.truncated = true;
861					excess -= length;
862					$el.remove();
863					return;
864				}
865
866				// Remove the excess text and append the ellipsis.
867				if (el.nodeType === 3) {
868					// should we finish the block anyway?
869					if (o.finishBlock) {
870						$(el.splitText(length)).replaceWith(o.ellipsis);
871					} else {
872						$(el.splitText(length - excess - 1)).replaceWith(o.ellipsis);
873					}
874					return false;
875				}
876
877				// Recursively truncate child nodes.
878				$el.truncate($.extend(o, { length: length - excess }));
879				return false;
880			});
881		});
882	};
883
884	$.truncate.defaults = {
885		// Strip all html elements, leaving only plain text.
886		stripTags: false,
887
888		// Only truncate at word boundaries.
889		words: false,
890
891		// When 'words' is active, keeps the first word in the string
892		// even if it's longer than a target length.
893		keepFirstWord: false,
894
895		// Replace instances of <br> with a single space.
896		noBreaks: false,
897
898		// if true always truncate the content at the end of the block.
899		finishBlock: false,
900
901		// The maximum length of the truncated html.
902		length: Infinity,
903
904		// The character to use as the ellipsis.  The word joiner (U+2060) can be
905		// used to prevent a hanging ellipsis, but displays incorrectly in Chrome
906		// on Windows 7.
907		// http://code.google.com/p/chromium/issues/detail?id=68323
908		ellipsis: '\u2026' // '\u2060\u2026'
909	};
910
911})(jQuery);

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.