PageSourceSearch

https://famobra.com/Files/Templates/Designs/Swift/Assets/js/custom.js?hash=1476235866

js famobra.com collected 2026-10-08 20:56:29 UTC 29,025 bytes, 741 lines download raw bytes

1var ContainerApi = (function () {
2	var onModalOkCallback;
3	var minicartPageId = 0;
4	// palletWidth and palletLength are in centimeters
5	const palletWidth = 80;
6	const palletLength = 120;
7	const volumeConversionFactor = 1000000;
8	getFloat = function (n) {
9		if (typeof (n) == "number") {
10			return n;
11		}
12
13		return parseFloat(n.replace(",", "."));
14	};
15
16	getInt = function (n) {
17		if (typeof (n) == "number") {
18			return Math.floor(n);
19		}
20
21		return parseInt(n.replace(",", "."));
22	};
23	getUrl = function () {
24		return "/Default.aspx?ID=" + minicartPageId;
25	};
26	calculateVolume = function (heightPerCase, numberOfLayers) {
27		// Returning the volume converted from cubic centimeters to cubic meters
28		return (numberOfLayers * palletWidth * palletLength * heightPerCase) / volumeConversionFactor;
29	};
30
31	calculateWeight = function (numberOfLayers, casesPerLayer, weightPerCase) {
32		return numberOfLayers * casesPerLayer * weightPerCase;
33	};
34	calculatePallets = function (numberOfLayers, casesPerLayer, casesPerPallet, doubleStack) {
35		var adq = ((casesPerLayer / casesPerPallet) * numberOfLayers);
36		var flooradq = Math.floor((casesPerLayer / casesPerPallet) * numberOfLayers);
37		var calculateLayer = adq - flooradq;
38		if (doubleStack == "True") {
39			if (numberOfLayers) {
40				if (calculateLayer <= 0.5) {
41					return flooradq + 0.5;
42				}
43				if (calculateLayer > 0.5) {
44					return flooradq + 1;
45				}
46			}
47
48			else {
49				return ((casesPerLayer / casesPerPallet) * numberOfLayers) / 2;
50			}
51		}
52		else {
53			return (casesPerLayer / casesPerPallet) * numberOfLayers;
54		}
55
56	};
57	containerVolumeCalculation = function (containerInfo, heightPerCase, casesPerLayer, casesPerPallet, isPallet) {
58		var quantity = 0;
59		var remainingVolume = getFloat(containerInfo.maxVolume) - getFloat(containerInfo.currentVolume);
60		var volumePerLayer = palletWidth * palletLength * heightPerCase;
61
62		if (remainingVolume < 0) {
63			return quantity;
64		}
65
66		if (isPallet) {
67			quantity = remainingVolume / ((volumePerLayer * (casesPerPallet / casesPerLayer) / volumeConversionFactor));  // Converting from cubic centimeters to cubic meters
68		} else {
69			quantity = remainingVolume / (volumePerLayer / volumeConversionFactor);  // Converting from cubic centimeters to cubic meters
70		}
71
72		return quantity;
73	};
74
75	containerWeightCalculation = function (containerInfo, weightPerCase, casesPerLayer, casesPerPallet, isPallet) {
76		var quantity = 0;
77		var remainingWeight = getFloat(containerInfo.maxWeight) - getFloat(containerInfo.currentWeight);
78		if (remainingWeight < 0) {
79			return quantity;
80		}
81		else {
82			if (isPallet) {
83				quantity = remainingWeight / (weightPerCase * casesPerPallet);
84			} else {
85				quantity = remainingWeight / (weightPerCase * casesPerLayer);
86			}
87
88			return getInt(quantity);
89		}
90
91	};
92	TruckPalletsCalculation = function (containerInfo, casesPerLayer, isPallet, casesPerPallet, doubleStack) {
93		var quantity = 0;
94		var remainingPallets = getFloat(containerInfo.maxPallets) - getFloat(containerInfo.countpallets);
95
96		if (isPallet) {
97			if (doubleStack == "True") {
98				quantity = (remainingPallets * casesPerPallets) * 2;
99			}
100			else {
101				quantity = remainingPallets * casesPerPallets;
102			}
103
104
105		} else {
106			if (doubleStack == "True") {
107				quantity = (remainingPallets * (casesPerPallet / casesPerLayer)) * 2;
108			}
109			else {
110				quantity = remainingPallets * (casesPerPallet / casesPerLayer);
111			}
112		}
113
114		return quantity;
115	};
116	getRemainingQuantityToFillContainer = function (containerInfo, weightPerCase, casesPerLayer, casesPerPallet, heightPerCase, unitId, doubleStack) {
117
118		var isPallet = unitId == "VO60" ? true : false;
119		var remainingVolume = 0;
120		var remainingPallets = 0;
121		var remainingWeight = containerWeightCalculation(containerInfo, getFloat(weightPerCase), getInt(casesPerLayer), getInt(casesPerPallet), isPallet);
122		var boolValue = (/true/i).test(containerInfo.iscontainer);
123
124		var boolValueDoubleStack = (/True/i).test(doubleStack);
125		if (isPallet) {
126			remainingPallets = containerInfo.maxPallets - containerInfo.countpallets;
127
128			if (boolValueDoubleStack) {
129				remainingPallets = (containerInfo.maxPallets - containerInfo.countpallets) * 2;
130			}
131
132		}
133		else {
134			remainingPallets = TruckPalletsCalculation(containerInfo, getInt(casesPerLayer), isPallet, getInt(casesPerPallet), doubleStack)
135			if (boolValueDoubleStack) {
136				remainingPallets = TruckPalletsCalculation(containerInfo, getInt(casesPerLayer), isPallet, getInt(casesPerPallet), doubleStack);
137			}
138		}
139
140		if (boolValue) {
141			remainingVolume = containerVolumeCalculation(containerInfo, getFloat(heightPerCase), getInt(casesPerLayer), getInt(casesPerPallet), isPallet);
142			return Math.floor(Math.min(remainingVolume, remainingWeight));
143		}
144
145		if (!boolValue) {
146
147			return Math.floor(Math.min(remainingPallets, remainingWeight));
148		}
149	};
150
151	postUpdatedContainerChoice = function (containerId, transporttype, reorder) {
152
153		Fetch.post(getUrl() + "&ContainerChoice=" + containerId + "&Trans
153portType=" + transporttype + (reorder ? "&reorder=" + reorder : ""), null, function () {
154		});
155
156	};
157	return {
158		config: function (config) {
159			minicartPageId = config.minicartPageId;
160			containerPageId = config.feedPageId;
161		},
162		calculateChoosenProductsMetrics: function (quantity, unitId, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, doubleStack) {
163			var layers = getInt(quantity);
164
165			// TODO: UnitID is EmptyString, so this needs to be validated after different units are added. Change unitId to point to pallet
166			if (unitId == "VO60") {
167				layers = Math.floor((layers * getInt(casesPerPallet)) / getInt(casesPerLayer));
168			}
169			var volume = calculateVolume(getFloat(heightPerCase), layers);
170			var weight = calculateWeight(layers, getInt(casesPerLayer), getFloat(weightPerCase));
171			var pallets = calculatePallets(layers, getInt(casesPerLayer), getInt(casesPerPallet), doubleStack);
172			return [volume, weight, pallets];
173		},
174		showContainerModal: function (e, productId, quantity, unitid, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, showModal, cWeight, cVolume, cPallets, mWeight, mVolume, mPallets, doubleStack, containerChoice, fillcart, cartExist) {
175			var target = e.target;
176			var cExist = cartExist;
177			//var calculations = ContainerApi.calculateChoosenProductsMetrics(quantity, unitid, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, doubleStack);
178			//var volume = calculations[0];
179			//var weight = calculations[1];
180			//var pallets = calculations[2];
181			//var currentWeight = getFloat(cWeight);
182			//var currentVolume = getFloat(cVolume);
183			//var currentPallets = getFloat(cPallets);
184			//var maxWeight = getFloat(mWeight);
185			//var maxVolume = getFloat(mVolume);
186			//var maxPallets = getFloat(mPallets);
187			document.getElementById("ModalContainer_" + productId).setAttribute("data-pid", productId);
188			document.getElementById("ModalContainer_" + productId).setAttribute("data-event", "add");
189			document.getElementById("ModalContainer_" + productId).setAttribute("data-doubleStack", doubleStack);
190			document.getElementById("ModalContainer_" + productId).setAttribute("data-weightpercase", weightPerCase);
191			document.getElementById("ModalContainer_" + productId).setAttribute("data-casesperlayer", casesPerLayer);
192			document.getElementById("ModalContainer_" + productId).setAttribute("data-casesperpallet", casesPerPallet);
193			document.getElementById("ModalContainer_" + productId).setAttribute("data-heightpercase", heightPerCase);
194			document.getElementById("ModalContainer_" + productId).setAttribute("data-unitid", unitid);
195			document.getElementById("ModalContainer_" + productId).classList.add("addtocart");
196			document.getElementById("ModalContainer_" + productId).classList.remove("filltocart");
197			document.getElementById("ModalContainer_" + productId).setAttribute("data-cartexist", cartExist);
198			var isFormValid = false;
199
200			if (getFloat(weightPerCase) > 0 && getFloat(heightPerCase) > 0 && unitid != "") {
201				isFormValid = true;
202			}
203
204
205			if (isFormValid) {
206
207			/*(weight + currentWeight) < maxWeight && (volume + currentVolume) < maxVolume - Show popup if space not enought*/ 
208				if (cExist==="true") {
209					ContainerApi.updateContainerChoice(productId, quantity, unitid, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, true, cartExist)
210				} else {
211					
212					document.getElementById('ShowContainersPopup_' + productId).click();
213				}
214
215			}
216		},
217
218		selectContainer: function (l) {
219			var fakeAddToCartContainer = document.querySelector(".fake_add-to-cart");
220			
221			const transportType = fakeAddToCartContainer.querySelector("input[name='TransportType']");
222			const containerChoice = fakeAddToCartContainer.querySelector("input[name='ContainerChoice']");
223			if (l.checked = true) {
224				transportType.value = l.dataset["transporttype"];
225				containerChoice.value = l.value;
226			}
227		},
228		updateContainerChoice: function (productId, quantity, unitid, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, showModal, isCart) {
229			var modalShownAdd = document.querySelector('.modal.addtocart');
230			var modalShownFill = document.querySelector('.modal.filltocart');
231		
232			var cartExist = isCart === "" ? true : isCart;
233			
234			var pid = productId;
235			if (modalShownAdd != null) {
236				cartExist = modalShownAdd.dataset["cartexist"] === "false" ? false : true;
237				pid = modalShownAdd.dataset["productid"];
238			}
239			if (modalShownFill != null) {
240				cartExist = modalShownFill.dataset["cartexist"] === "false" ? false : true;
241				pid = modalShownFill.dataset["productid"];
242			}
243			if (pid == undefined) {
244				pid = "";
245			}
246			var myModalEl = document.getElementById('ModalContainer_' + pid);
247			var modal = bootstrap.Modal.getInstance(myModalEl);
248			
249			if (myModalEl) {
250				doubleStack = document.getElementById("ModalContainer_" + pid).getAttribute("data-doublestack");
251				cPerLayer = document.getElementById("ModalContainer_" + pid).getAttribute("data-casesperlayer");
252				hPerCase = document.getElementById("ModalContainer_" + pid).getAttribute("data-heightpercase");
253				wPerCase = document.getElementById("ModalContainer_" + pid).getAttribute("data-weightpercase");
254				cPerPallet = document.getElementById("ModalContainer_" + pid).getAttribute("data-casesperpallet");
255				uid = document.getElementById("ModalContainer_" + pid).getAttribute("data-unitid");
256			}
257			
258			
259			var selectedContainer;
260			if (document.querySelector('.container-modal-box input[type=radio]:checked')) {
261				selectedContainer = document.querySelector('.container-modal-box input[type=radio]:checked');
262			}
263			if (selectedContainer != null) {
264				if (modalShownAdd!=null) {
265					if (document.querySelector("#AddToCartButtonContainer_" + pid) != null) {
266						if (!cartExist) {
267							swift.Cart.Update(document.querySelector("#AddToCartButtonContainer_" + pid));
268							if (modalShownAdd.classList.contains("show")) {
269								modal.hide();
270							}
271							postUpdatedContainerChoice(selectedContainer.value, selectedContainer.dataset["transporttype"]);
272							location.reload()
273
274								
275							} else {
276								
277								swift.Cart.Update(document.querySelector("#AddToCartButtonContainer_" + pid));
278								if (modalShownAdd.classList.contains("show")) {
279									modal.hide();
280							}
281							/*postUpdatedContainerChoice(selectedContainer.value, selectedContainer.dataset["transporttype"]);*/
282								/*location.reload()*/
283							}
284						}
285						else {
286							document.querySelector("#ordersubmit").submit();
287
288						}
289				}
290				else {
291				
292					quantity = getRemainingQuantityToFillContainer({
293						maxWeight: selectedContainer.dataset.maxweight,
294						maxVolume: selectedContainer.dataset.maxvolume,
295						currentVolume: 0,
296						currentWeight: 0,
297						maxPallets: selectedContainer.dataset.maxpallets,
298						countpallets: 0,
299						iscontainer: selectedContainer.dataset.iscontainer
300					}, wPerCase, cPerLayer, cPerPallet, hPerCase, uid, doubleStack);
301				
302					if (quantity > 0) {
303						if (!cartExist) {
304							document.getElementById("Quantity_" + pid + "_").value = quantity;
305							if (document.querySelector("#AddToCartFillContainer_" + pid) != null) {
306								swift.Cart.Update(document.querySelector("#AddToCartFillContainer_" + pid));
307								
308								if (modalShownFill.classList.contains("show")) {
309									modal.hide();
310								}
311								postUpdatedContainerChoice(selectedContainer.value, selectedContainer.dataset["transporttype"]);
312								location.reload();
313							}
314							//Fetch.get(`${location.href}&cartcmd=createnew`, function () {
315							//	postUpdatedContainerChoice(selectedContainer.value, selectedContainer.dataset["transporttype"]);
316
317							//	document.getElementById("Quantity_" + pid + "_").value = quantity;
318							//	if (document.querySelector("#AddToCartFillContainer_" + pid) != null) {
319							//		swift.Cart.Update(document.querySelector("#AddToCartFillContainer_" + pid));
320							//		if (modalShownFill.classList.contains("show")) {
321							//			modal.hide();
322							//		}
323							//		location.reload();
324							//	}
325
326							//})
327						} else {
328							document.getElementById("Quantity_" + pid + "_").value = quantity;
329							if (document.querySelector("#AddToCartFillContainer_" + pid) != null) {
330								swift.Cart.Update(document.querySelector("#AddToCartFillContainer_" + pid));
331								if (modalShownFill.classList.contains("show")) {
332									modal.hide();
333								}
334								location.reload();
335							}
336						}
337					
338					}
339				}
340				
341			}
342			else {
343				
344				if (modalShownAdd != null) {
345					if (document.querySelector("#AddToCartButtonContainer_" + pid) != null) {
346						
347						swift.Cart.Update(document.querySelector("#AddToCartButtonContainer_" + pid));
348						if (modalShownAdd.classList.contains("show")) {
349							modal.hide();
350						}
351						location.reload()
352					}
353				}
354				if (modalShownFill != null) {
355					quantity = getRemainingQuantityToFillContainer({
356						maxWeight: mWeight,
357						maxVolume: mVolume,
358						maxPallets: mPallets,
359						currentVolume: cVolume,
360						currentWeight: cWeight,
361						countpallets: cPallets,
362						iscontainer: iscontainer
363					}, weightPerCase, casesPerLayer, casesPerPallet, heightPerCase, unitid, doubleStack);
364
365					if (quantity > 0) {
366						document.getElementById("Quantity_" + pid + "_").value = quantity;
367						if (document.querySelector("#AddToCartFillContainer_" + pid) != null) {
368							swift.Cart.Update(document.querySelector("#AddToCartFillContainer_" + pid));
369							if (modalShownFill.classList.contains("show")) {
370								modal.hide();
371							}
372							location.reload()
373							
374						}
375					}
376				}
377			}
378
379		},
380
381		fillCart: function (e, productId, unitid, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, showModal, cWeight, cVolume, cPallets, mWeight, mVolume, mPallets, doubleStack, containerChoice, iscontainer, fillcart, cartExist) {
382			var target = e.target;
383			var quantity = 1;
384			var isFormValid = false;
385			document.getElementById("ModalContainer_" + productId).setAttribute("data-pid", productId);
386			document.getElementById("ModalContainer_" + productId).setAttribute("data-event", "add");
387			document.getElementById("ModalContainer_" + productId).setAttribute("data-doubleStack", doubleStack);
388			document.getElementById("ModalContainer_" + productId).setAttribute("data-weightpercase", weightPerCase);
389			document.getElementById("ModalContainer_" + productId).setAttribute("data-casesperlayer", casesPerLayer);
390			document.getElementById("ModalContainer_" + productId).setAttribute("data-casesperpallet", casesPerPallet);
391			document.getElementById("ModalContainer_" + productId).setAttribute("data-heightpercase", heightPerCase);
392			document.getElementById("ModalContainer_" + productId).setAttribute("data-unitid", unitid);
393			document.getElementById("ModalContainer_" + productId).classList.add("filltocart");
394			document.getElementById("ModalContainer_" + productId).classList.remove("addtocart");
395			document.getElementById("ModalContainer_" + productId).setAttribute("data-cartexist", cartExist);
396			if (getFloat(weightPerCase) > 0 && getFloat(heightPerCase) > 0 && unitid != "") {
397				isFormValid = true;
398			}
399
400			if (isFormValid) {
401				if (containerChoice == "") {				
402					document.getElementById('ShowContainersPopup_' + productId).click();
403				}
404				else {
405					ContainerApi.fillContainerChoice(e, productId, unitid, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, showModal, cWeight, cVolume, cPallets, mWeight, mVolume, mPallets, doubleStack, containerChoice, iscontainer)
406				}
407
408
409			}
410		},
411		fillContainerChoice(e, productId, unitid, casesPerPallet, casesPerLayer, heightPerCase, weightPerCase, showModal, cWeight, cVolume, cPallets, mWeight, mVolume, mPallets, doubleStack, containerChoice, iscontainer, fillcart, cartExist) {
412			{
413				var modalShownFill = document.querySelector('.modal.show.filltocart');
414				var pid = productId;
415				if (modalShownFill != null) {
416					pid = modalShownFill.dataset["productid"];
417				}
418				if (pid == undefined) {
419					pid = "";
420				}
421				var selectedContainer;
422				if (document.querySelector('.container-modal-box input[type=radio]:checked')) {
423					selectedContainer = document.querySelector('.container-modal-box input[type=radio]:checked');
424				}
425				if (selectedContainer) {
426					quantity = getRemainingQuantityToFillContainer({
427						maxWeight: selectedContainer.dataset.maxweight,
428						maxVolume: selectedContainer.dataset.maxvolume,
429						currentVolume: 0,
430						currentWeight: 0,
431						maxPallets: selectedContainer.dataset.maxpallets,
432						countpallets: 0,
433						iscontainer: selectedContainer.dataset.iscontainer
434					}, weightPerCase, casesPerLayer, casesPerPallet, heightPerCase, unitid, doubleStack);
435					if (quantity > 0) {
436						document.getElementById("Quantity_" + pid + "_").value = quantity;
437						if (document.querySelector("#AddToCartFillContainer_" + pid) != null) {
438							swift.Cart.Update(document.querySelector("#AddToCartFillContainer_" + pid));
439							if (modalShownFill  != null) {
440								modal.hide();
441							}
442							location.reload()
443						}
444					}
445				}
446				else {
447					quantity = getRemainingQuantityToFillContainer({
448						maxWeight: mWeight,
449						maxVolume: mVolume,
450						maxPallets: mPallets,
451						currentVolume: cVolume,
452						currentWeight: cWeight,
453						countpallets: cPallets,
454						iscontainer: iscontainer
455					}, weightPerCase, casesPerLayer, casesPerPallet, heightPerCase, unitid, doubleStack);
456
457					if (quantity > 0) {
458						document.getElementById("Quantity_" + pid + "_").value = quantity;
459						if (document.querySelector("#AddToCartFillContainer_" + pid) != null) {
460							swift.Cart.Update(document.querySelector("#AddToCartFillContainer_" + pid));
461							if (modalShownFill  != null) {
462								modal.hide();
463							}
464							location.reload()
465						}
466					}
467
468				}
469			}
470		}
471	}
472})();
473
474
475window.customSwift = ContainerApi;
476
477var Fetch = (function () {
478
479	const request = function (url, method, data, success, error) {
480		var xhr = new XMLHttpRequest();
481		xhr.open(method, url, true);
482		xhr.onreadystatechange = function () {
483			if (this.readyState == XMLHttpRequest.DONE && this.status == 200) {
484				var data;
485
486				if (this.responseType === 'json') {
487					data = this.response.message;
488				} else {
489					data = this.response;
490				}
491
492				if (typeof (success) == "function") {
493					success(data);
494				}
495			} else if (this.readyState == XMLHttpRequest.DONE && this.status != 200) {
496				if (typeof (error) == "function") {
497					error(this.response);
498				}
499			}
500		};
501		xhr.setRequestHeader('cache-control', 'no-cache, must-revalidate, post-check=0, pre-check=0');
502		xhr.setRequestHeader('cache-control', 'max-age=0');
503		xhr.setRequestHeader('expires', '0');
504		xhr.setRequestHeader('expires', 'Tue, 01 Jan 1980 1:00:00 GMT');
505		xhr.setRequestHeader('pragma', 'no-cache');
506		if (data) {
507			xhr.send(JSON.stringify(data));
508		} else {
509			xhr.send();
510		}
511	};
512
513	return {
514		get: function (url, success, error) {
515			request(url, "GET", null, success, error);
516		},
517
518		post: function (url, data, success, error) {
519			request(url, "POST", data, success, error);
520		},
521
522		getJSON: function (url, success) {
523			request(url, "GET", null, function (json) {
524				var data = JSON.parse(json);
525				if (typeof (success) == "function") {
526					success(data);
527				}
528			});
529		}
530	};
531})();
532const CustomTypeahead = function () {
533	var tabIndex = -1;
534	var tabIndexOld = 0;
535	var timeout;
536	var controller = new AbortController();
537	return {
538		suggest: function (e, searchField) {
539			if (e.key === "ArrowUp" || e.key === "ArrowDown") {
540				// handle dropdown navigation if present
541				document.querySelectorAll(".js-type-ahead-menu").forEach(function (menu) {
542					if (menu.classList.contains("show")) {
543						CustomTypeahead.debounce(() => CustomTypeahead.handleArrowNavigation(e.key, menu), 50)();
544						return;
545					}
546				});
547			} else {
548				tabIndex = -1;
549				if (searchField.value.length > 0) {
550					var val = searchField.value;
551					document.querySelectorAll(".js-type-ahead-field").forEach(function (field) {
552						field.setAttribute("data-original", val)
553					});
554					CustomTypeahead.debounce(() => CustomTypeahead.getSuggestions(searchField), 300)();
555				} else {
556					CustomTypeahead.hideSearchResults();
557				}
558			}
559			if (e.key === "Escape") {
560				// Revert back to the original value last entered in the input field
561				const highlightedItems = userList.querySelectorAll(".highlighted");
562				document.querySelectorAll(".js-type-ahead-field").forEach(function (field) {
563					field.value = field.getAttribute("data-original");
564				});
565				CustomTypeahead.hideSearchResults();
566				return;
567			}
568			if (e.key === "Tab") {
569				return;
570			}
571		},
572		handleTab: function (e) {
573			if (e.key === "Tab") {
574				//keep selection from dropdown navigation but do not submit search
575				CustomTypeahead.hideSearchResults();
576				return;
577			}
578		},
579		handleArrowNavigation: function (key, menu) {
580			var elements = menu.getElementsByClassName("dropdown-item");
581			if (!elements || elements.length < 1) {
582				return;
583			}
584			if (key === "ArrowUp") {
585				tabIndex--;
586			} else {
587				tabIndex++;
588			}
589			if (tabIndex < 0 || tabIndex > elements.length - 1) {
590				tabIndex = 0;
591			}
592			menu.setAttribute("data-tabindex", tabIndex);
593			if (tabIndex > -1) {
594				elements[tabIndex].classList.add("active");
595				var suggestionElement = elements[tabIndex];
596				CustomTypeahead.preSelectSuggestion(suggestionElement);
597				if (tabIndexOld != tabIndex && elements[tabIndexOld]) {
598					elements[tabIndexOld].classList.remove("active");
599				}
600				tabIndexOld = tabIndex;
601			}
602		},
603		getSuggestions: async function (searchField) {
604			var resultsPageId = searchField.closest(".js-suggest-form").getAttribute("data-search-results-page");
605			var defaultDetailsPageId = searchField.closest(".js-suggest-form").getAttribute("data-product-details-page-id");
606			var searchUrl = "/Default.aspx?ID=" + resultsPageId + "&defaultpdpId=" + defaultDetailsPageId + "&redirect=false&eq=" + encodeURIComponent(searchField.value.toLowerCase());
607			const signal = controller.signal;
608			let abortError = false;
609			let response = await fetch(searchUrl, { signal }).catch(function (error) {
610				abortError = true;
611			});
612			if (!abortError) {
613				if (!response.ok) {
614					throw new Error(`HTTP error! status: ${response.status}`);
615				} else {
616					let html = await response.text().then(function (text) {
617						return text;
618					});
619					var parser = new DOMParser();
620					var doc = parser.parseFromString(html, 'text/html');
621					var listElements = doc.querySelectorAll("li");
622					CustomTypeahead.displaySuggestions(listElements, searchField);
623				}
624			}
625		},
626		displaySuggestions: function (listElements, searchField) {
627			if (listElements.length > 0) {
628				var closestDropdown = searchField.closest(".js-type-ahead-dropdown");
629				var dropdownMenu = closestDropdown.querySelector(".js-type-ahead-menu");
630				dropdownMenu.innerHTML = "";
631				listElements.forEach(function (element) {
632					dropdownMenu.appendChild(element)
633				});
634				CustomTypeahead.showSearchResults(searchField);
635			}
636		},
637		selectSuggestion_: function (inputValue) {
638			document.querySelectorAll(".js-type-ahead-field").forEach(function (field) {
639				field.value = inputValue;
640				if (field.value != "") {
641					elm.closest(".js-type-ahead-dropdown").querySelector(".js-suggest-form").submit();
642				}
643			});
644		},
645		preSelectSuggestion: function (elm) {
646			var suggestionElement = elm.querySelector(".js-suggestion");
647			document.querySelectorAll(".js-type-ahead-field").forEach(function (field) {
648				field.value = suggestionElement.innerText;
649				field.focus();
650				var formElm = field.closest(".js-suggest-form");
651				var parm = formElm.querySelector(".js-type-ahead-parameter");
652				if (elm.getAttribute("data-param") && elm.getAttribute("data-paramvalue")) {
653					if (elm.getAttribute("data-param").includes("ProductId") || elm.getAttribute("data-param").includes("ID")) {
654						var productDetailPage = formElm.getAttribute("data-product-details-page");
655						productDetailPage = elm.getAttribute("data-selected-details-page") != null ? elm.getAttribute("data-selected-detail
655s-page") : productDetailPage;
656						formElm.method = "post";
657						formElm.setAttribute("action", productDetailPage);
658					} else {
659						parm.setAttribute("name", elm.getAttribute("data-param"));
660						parm.setAttribute("value", elm.getAttribute("data-paramvalue"));
661						var productListPage = formElm.getAttribute("data-product-list-page");
662						formElm.setAttribute("action", productListPage);
663					}
664				} else {
665					parm.removeAttribute("name");
666					parm.removeAttribute("value");
667					var allResultsPage = formElm.getAttribute("data-product-list-page");
668					allResultsPage = elm.getAttribute("data-all-results-page") ? elm.getAttribute("data-all-results-page") : allResultsPage;
669					formElm.setAttribute("action", allResultsPage);
670				}
671			});
672		},
673		setSuggestion: function (elm) {
674			document.body.removeEventListener('click', CustomTypeahead.hideSearchResults, false);
675			CustomTypeahead.preSelectSuggestion(elm);
676			var searchField = elm.closest(".js-type-ahead-dropdown").querySelector(".js-type-ahead-field");
677			if (searchField) {
678				CustomTypeahead.showSearchResults(searchField);
679			}
680			var hideSearchTimer = setTimeout(function () {
681				document.body.addEventListener('click', CustomTypeahead.hideSearchResults);
682			}, 200);
683		},
684		selectSuggestion: function (elm) {
685			CustomTypeahead.preSelectSuggestion(elm);
686			elm.closest(".js-type-ahead-dropdown").querySelector(".js-suggest-form").submit();
687		},
688		showSearchResults: function (searchField) {
689			var closestDropdown = searchField.closest(".js-type-ahead-dropdown");
690			var menu = closestDropdown.querySelector(".js-type-ahead-menu");
691			if (menu.innerHTML != "") {
692				menu.classList.add("show");
693			}
694			closestDropdown.classList.add("show");
695			var hideSearchTimer = setTimeout(function () {
696				document.body.addEventListener('click', CustomTypeahead.hideSearchResults);
697			}, 200);
698		},
699		hideSearchResults: function () {
700			document.querySelectorAll(".js-type-ahead-dropdown").forEach(function (dropdown) {
701				dropdown.classList.remove("show");
702			});
703			document.querySelectorAll(".js-type-ahead-menu").forEach(function (dropdown) {
704				dropdown.classList.remove("show");
705			});
706		},
707		debounce: function (func, wait, immediate) {
708			return function () {
709				controller.abort();
710				controller = new AbortController();
711				var context = this, args = arguments;
712				var later = function () {
713					timeout = null;
714					if (!immediate) func.apply(context, args);
715				};
716				var callNow = immediate && !timeout;
717				clearTimeout(timeout);
718				timeout = setTimeout(later, wait);
719				if (callNow) func.apply(context, args);
720			};
721		},
722		goToPage: function (aTag) {
723			var pageTitle = aTag.getAttribute("title");
724			CustomTypeahead.navigateToPage(aTag.href);
725			history.pushState(null, pageTitle, aTag.href);
726			if (pageTitle != null) {
727				document.title = pageTitle;
728			}
729			return false;
730		},
731		navigateToPage: async function (href) {
732		},
733		init: function () {
734			document.querySelectorAll(".js-type-ahead-field").forEach(function (field) {
735				field.addEventListener('keyup', (e) => CustomTypeahead.suggest(e, field))
736				field.addEventListener('keydown', (e) => CustomTypeahead.handleTab(e));
737			});
738		}
739	}
740}();
741window.customType = CustomTypeahead;

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.