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,G","sources":["webpack://On2netWebsiteFramework/./src/js/search.js"],"sourcesContent":["import { autocomplete } from '@algolia/autocomplete-js';\r\n\r\n\r\ndocument.addEventListener( 'DOMContentLoaded', function() {\r\n\r\n function debouncePromise(fn, time){\r\n let timerId = undefined\r\n \r\n return function(...args){\r\n if(timerId){\r\n clearTimeout(timerId)\r\n } \r\n return new Promise((resolve) => {\r\n timerId = setTimeout(() => resolve(fn(...args)), time)\r\n }) \r\n }\r\n }\r\n const debouncedFetch = debouncePromise(fetch, 300) \r\n\r\n if(document.getElementById(\"searchField\")){\r\n \r\n autocomplete({\r\n container: '#searchField',\r\n placeholder: 'Search for products',\r\n //debug: true,\r\n \r\n getSources({query}){\r\n return debouncedFetch(`/ajax/search?q=${query}`)\r\n .then(response => response.json())\r\n .then((data) => {\r\n return [\r\n {\r\n sourceId: \"lines\",\r\n getItems(){\r\n return data\r\n }, \r\n getItemUrl({ item }) {\r\n return `/product/shop/${item.Id}/${seoURL(item.name)}`\r\n }, \r\n templates: {\r\n item({ item, html }){ \r\n return html`\r\n
\r\n
\r\n \r\n
\r\n
\r\n ${item.name} \r\n
\r\n
£${getPrice(item.offer_price)}
\r\n
\r\n
`\r\n },\r\n // footer(){\r\n // return \"FOOTER\"\r\n // },\r\n noResults(){\r\n return \"No results\"\r\n }\r\n }\r\n }\r\n ] \r\n })\r\n }\r\n });\r\n \r\n }\r\n\r\n function getImage(filename){\r\n if(filename==0){\r\n return \"/assets/images/no-image-s.jpg\"\r\n } else {\r\n return `https://nuenta.com/product_pics/${filename}.jpg`\r\n }\r\n }\r\n \r\n function getPrice(minPrice){\r\n if(minPrice==0){return ' CALL';}else{ return minPrice.toFixed(2);}\r\n }\r\n function seoURL(url) {\r\n return url.toString() // Convert to string\r\n .normalize('NFD') // Change diacritics\r\n .replace(/[\\u0300-\\u036f]/g,'') // Remove illegal characters\r\n .replace(/\\s+/g,'-') // Change whitespace to dashes\r\n .toLowerCase() // Change to lowercase\r\n .replace(/&/g,'-and-') // Replace ampersand\r\n .replace(/[^a-z0-9\\-]/g,'') // Remove anything that is not a letter, number or dash\r\n .replace(/-+/g,'-') // Remove duplicate dashes\r\n .replace(/^-*/,'') // Remove starting dashes\r\n .replace(/-*$/,''); // Remove trailing dashes\r\n } \r\n\r\n\r\n});"],"names":["document","addEventListener","debouncedFetch","fn","time","timerId","args","clearTimeout","Promise","resolve","setTimeout","debouncePromise","fetch","seoURL","url","toString","normalize","replace","toLowerCase","getElementById","autocomplete","container","placeholder","getSources","query","then","response","json","data","sourceId","getItems","getItemUrl","item","Id","name","templates","html","filename","imgID","minPrice","offer_price","toFixed","noResults"],"sourceRoot":""}