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AAKgB,gBAAgBS,OAAS,KAC1BzB,KAAKwB,iBAAgB,EAAM,EAGvC,CAEAA,eAAAA,CAAgBE,GAETA,EACC1B,KAAKkB,YAAcS,aAAY,KAC3B3B,KAAK4B,iBAAgB,EAAK,GAC3B,MAEHC,cAAc7B,KAAKkB,aACnBlB,KAAKkB,YAAc,KAE3B,CAEAU,eAAAA,CAAgBE,GAAgB,GAC5B9B,KAAKoB,eAAiBpB,KAAKmB,WAC3B,IAAIY,EAAgB/B,KAAKgB,gBAAgBgB,MAAMC,cAAcC,OACzDC,EAAiBJ,EAAcK,OAAS,EAAIL,EAAgB,GAC7DI,GAAkBnC,KAAKoB,iBACtBpB,KAAKmB,WAAagB,EACfL,IAAe9C,EAAAA,EAAAA,UAASgB,KAAKqC,SAAU,KAElD,CAEAA,MAAAA,GAC0B,IAAnBrC,KAAKmB,WAhDhBmB,eAAgCC,GAC5B,mBAAoB9B,OAAO+B,MAAMhC,EAAsB+B,IAAeE,MAC1E,CA+CYC,CAAiB1C,KAAKmB,YAAYwB,MAAMC,IACtB,IAAXA,GACC5C,KAAKqB,eAAewB,UAAYD,EAChC5C,KAAKqB,eAAeyB,aAAa,cAAc,SAC/C9C,KAAKsB,eAAgB,IAErBtB,KAAKqB,eAAewB,UAAY,GAChC7C,KAAKqB,eAAeyB,aAAa,cAAc,QAC/C9C,KAAKsB,eAAgB,EACzB,KAGJtB,KAAKqB,eAAewB,UAAY,GAChC7C,KAAKqB,eAAeyB,aAAa,cAAc,QAC/C9C,KAAKsB,eAAgB,EAE7B,EAKG,SAASyB,EAAWC,GACvBA,EAASC,SAASC,IAEQ,IAAlBA,EAAKC,UACL,IAAItC,EAAWqC,EACnB,GAER,C","sources":["webpack://National Motor Museum Trust/./node_modules/debounce/index.js","webpack://National Motor Museum Trust/./wwwroot/app/src/js/collection-search-form.js"],"sourcesContent":["/**\n * Returns a function, that, as long as it continues to be invoked, will not\n * be triggered. The function will be called after it stops being called for\n * N milliseconds. If `immediate` is passed, trigger the function on the\n * leading edge, instead of the trailing. The function also has a property 'clear' \n * that is a function which will clear the timer to prevent previously scheduled executions. \n *\n * @source underscore.js\n * @see http://unscriptable.com/2009/03/20/debouncing-javascript-methods/\n * @param {Function} function to wrap\n * @param {Number} timeout in ms (`100`)\n * @param {Boolean} whether to execute at the beginning (`false`)\n * @api public\n */\nfunction debounce(func, wait, immediate){\n var timeout, args, context, timestamp, result;\n if (null == wait) wait = 100;\n\n function later() {\n var last = Date.now() - timestamp;\n\n if (last < wait && last >= 0) {\n timeout = setTimeout(later, wait - last);\n } else {\n timeout = null;\n if (!immediate) {\n result = func.apply(context, args);\n context = args = null;\n }\n }\n };\n\n var debounced = function(){\n context = this;\n args = arguments;\n timestamp = Date.now();\n var callNow = immediate && !timeout;\n if (!timeout) timeout = setTimeout(later, wait);\n if (callNow) {\n result = func.apply(context, args);\n context = args = null;\n }\n\n return result;\n };\n\n debounced.clear = function() {\n if (timeout) {\n clearTimeout(timeout);\n timeout = null;\n }\n };\n \n debounced.flush = function() {\n if (timeout) {\n result = func.apply(context, args);\n context = args = null;\n \n clearTimeout(timeout);\n timeout = null;\n }\n };\n\n return debounced;\n};\n\n// Adds compatibility for ES modules\ndebounce.debounce = debounce;\n\nmodule.exports = debounce;\n","import { debounce } from 'debounce';\r\n\r\n// endpoint where search data comes from\r\nconst collectionSearchURL = window.collectionSearchEndpoint.toString() + (window.collectionSearchEndpoint.toString().indexOf('?') > -1 ? '&q=' : '?q=');\r\n\r\n// Get from the cache, or make a new fetch request\r\nasync function getSearchResults(searchString) {\r\n return await (await window.fetch(collectionSearchURL + searchString)).text();\r\n}\r\n\r\nclass HelpSearch {\r\n\r\n constructor(el) {\r\n this.el = el;\r\n this.searchTextField = el.querySelector('input[type=\"search\"]');\r\n this.searchWatch = null;\r\n this.searchText = '';\r\n this.prevSearchText = '';\r\n this.resultsWrapper = el.querySelector('.collection-search-form--results');\r\n this.resultsActive = false;\r\n // watch the searchTextField\r\n if(this.searchTextField != null) {\r\n this.searchTextField.onfocus = () => {\r\n this.watchSearchText(true);\r\n };\r\n this.searchTextField.onblur = () => {\r\n this.watchSearchText(false);\r\n };\r\n }\r\n }\r\n\r\n watchSearchText(mode) {\r\n // search only kicks in if text is at least 3 chars\r\n if(mode) {\r\n this.searchWatch = setInterval(() => {\r\n this.checkSearchText(true);\r\n }, 200);\r\n } else {\r\n clearInterval(this.searchWatch);\r\n this.searchWatch = null;\r\n }\r\n }\r\n\r\n checkSearchText(triggerUpdate = false) {\r\n this.prevSearchText = this.searchText;\r\n let getSearchText = this.searchTextField.value.toLowerCase().trim(),\r\n workSearchText = getSearchText.length > 2 ? getSearchText : '';\r\n if(workSearchText != this.prevSearchText) {\r\n this.searchText = workSearchText;\r\n if(triggerUpdate) debounce(this.update(), 200);\r\n }\r\n }\r\n\r\n update() {\r\n if(this.searchText != '') {\r\n getSearchResults(this.searchText).then((content) => {\r\n if(content != '') {\r\n this.resultsWrapper.innerHTML = content;\r\n this.resultsWrapper.setAttribute('aria-hidden','false');\r\n this.resultsActive = true;\r\n } else {\r\n this.resultsWrapper.innerHTML = '';\r\n this.resultsWrapper.setAttribute('aria-hidden','true');\r\n this.resultsActive = false;\r\n }\r\n });\r\n } else {\r\n this.resultsWrapper.innerHTML = '';\r\n this.resultsWrapper.setAttribute('aria-hidden','true');\r\n this.resultsActive = false;\r\n }\r\n }\r\n\r\n}\r\n\r\n// export the default function to create\r\nexport function createFrom(wrappers) {\r\n wrappers.forEach((node) => {\r\n // if node is an element\r\n if (node.nodeType === 1) {\r\n new HelpSearch(node);\r\n }\r\n });\r\n}"],"names":["debounce","func","wait","immediate","timeout","args","context","timestamp","result","later","last","Date","now","setTimeout","apply","debounced","this","arguments","callNow","clear","clearTimeout","flush","module","exports","collectionSearchURL","window","collectionSearchEndpoint","toString","indexOf","HelpSearch","constructor","el","searchTextField","querySelector","searchWatch","searchText","prevSearchText","resultsWrapper","resultsActive","onfocus","watchSearchText","onblur","mode","setInterval","checkSearchText","clearInterval","triggerUpdate","getSearchText","value","toLowerCase","trim","workSearchText","length","update","async","searchString","fetch","text","getSearchResults","then","content","innerHTML","setAttribute","createFrom","wrappers","forEach","node","nodeType"],"sourceRoot":""}