Account
';}if(custHTML) {html += '
'+custHTML+'
';}}if(html) {searchPholder.innerHTML = html;reloadScripts("#pixie_search_placeholder");}}function setPmSearch(val) {if(val) {searchInput.value = val;var event = new Event('keyup');searchInput.dispatchEvent(event);}}function performSearch(query) { searchLoader.style.display = 'block'; fetch('/elasticpixie/index/search?q=' + encodeURIComponent(query), { }) .then(response => response.json()) .then(data => { buildResults(data,query); }) .catch(error => { if (error.name === 'AbortError') { // The request was aborted console.log('Search request aborted'); } else { console.error('Error:', error); } });}var debouncedperformSearch = debounce(function (query) { if (!isSearchInProgress) { isSearchInProgress = true; performSearch(query) setTimeout(function () { isSearchInProgress = false; }, 50); }}, 50);function buildResults(data,query) {var total = 0;var html = ''; searchResults.classList.add('shown');var allresults = data.results.hits.total.value;var hitsArray = data.results.hits.hits;hitsArray.forEach(function(hit) { var index = hit._index;var type = hit._type;var id = hit._id;var score = hit._score;var source = hit._source;// Now you can access properties within the 'source' objectvar enabled = source.status;if(enabled == 1) {total++;var item = (source.pixie_html && source.pixie_html.length)?source.pixie_html:false;if(item) {html += highlightAbstract(query,item);} else {console.log('Missing record for: '+id);}} });if(total > 0) {console.log(total+" results");var showing = (total < allresults)?'You\'ve viewed the first '+total+' results':'';var button = '
'+showing+'
';var totalHtml = ''+allresults+' PRODUCTS FOUND';var totalCounter = (allresults > 1)?allresults+' results':allresults+ ' result';//searchTitle.innerHTML = totalHtml;searchCounter.innerHTML = totalCounter;searchProducts.innerHTML = html+button;searchLoader.style.display = 'none';searchResults.style.display = 'block';updateFormKey();debouncedSetAjaxCart();reloadScripts("#pixie_products");searchPholder.innerHTML = '';} else {console.log("no results");searchResults.classList.remove('shown');searchCounter.innerHTML = '0 results';//searchResults.style.display = 'none';searchProducts.innerHTML = '';searchTitle.innerHTML = '';searchLoader.style.display = 'none';placeHolderPopulate();}}function debounce(func, delay) { let timeoutId; return function () { const context = this; const args = arguments; clearTimeout(timeoutId); timeoutId = setTimeout(function () { func.apply(context, args); }, delay); };}// Wrap setAjaxCart with debouncevar debouncedSetAjaxCart = debounce(function () { if (!isSetAjaxCartInProgress) { isSetAjaxCartInProgress = true; window.setAjaxCart(); setTimeout(function () { isSetAjaxCartInProgress = false; }, 100); }}, 100);function updateFormKey() {let formKey = hyva.getFormKey(); Array.from(document.querySelectorAll('input[name="form_key"]')).map(function (input) {console.log("setting"); input.value = formKey; });}function highlight(search,value) { search = search.trim(); var index = value.toLowerCase().indexOf(search.toLowerCase()); if (index >= 0) { value = value.substring(0,index) + "
" + value.substring(index,index+search.length) + "" + value.substring(index + search.length); return value; } // Now check if multiple words var searchWords = search.toLowerCase().split(/\s+/); for (var i = 0; i < searchWords.length; i++) { var searchWord = searchWords[i]; var index = value.toLowerCase().indexOf(searchWord); // Apply highlighting to each occurrence of the search word while (index >= 0) { value = value.substring(0, index) + "
" + value.substring(index, index + searchWord.length) + "" + value.substring(index + searchWord.length); index = value.toLowerCase().indexOf(searchWord, index + ("
".length + "".length)); } } return value;}function highlightAbstract(search,product) { var tempDiv = document.createElement('div'); tempDiv.innerHTML = product; var productName = tempDiv.querySelector('.product-item-link').innerHTML; var highlightName = highlight(search,productName); if(highlightName) { tempDiv.querySelector('.product-item-link').innerHTML = highlightName; return tempDiv.innerHTML; } return product; }// Attach event listener to input fieldlet debounceTimeout;searchInput.addEventListener('keyup', function(event) { const query = event.target.value; // Perform search only if the query is not empty if (query.length && query.trim() !== '') { //performSearch(query); debouncedperformSearch(query); } else {console.log("query empty");clearSearch(); }});function clearSearch() {searchController.abort();searchProducts.innerHTML = ''; searchTitle.innerHTML = ''; searchResults.classList.remove('shown');searchLoader.style.display = 'none';searchInput.value = '';}function submitSearch() {searchForm.submit();}// GENERIC LOAD SCRIPTS AFTER AJAX ACTIONfunction reloadScripts(element) {const container = document.querySelector(element);const scripts = container.querySelectorAll('script');scripts.forEach(script => { const newScript = document.createElement('script'); if (script.src) {newScript.src = script.src; // If the script has a src attribute, copy it } else {newScript.textContent = script.textContent; // Otherwise, copy the inline script content } document.head.appendChild(newScript); // Append the new script element to the document document.head.removeChild(newScript); // Optionally remove the script element after execution});}
See details
CHECKOUT
Continue Shopping
Same Day Engraving & Dispatch
60 Day Free Returns
Free Delivery Over £100