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AAxBxB,KAAKkB,kBACJlB,KAAKkB,gBAAgBO,QAAU,WAC3B,EAAKC,iBAAgB,EACxB,EACD1B,KAAKkB,gBAAgBS,OAAS,WAC1B,EAAKD,iBAAgB,EACxB,EAER,sDAED,SAAgBE,GAAM,WAEfA,EACC5B,KAAKoB,YAAcS,aAAY,WAC3B,EAAKC,iBAAgB,EACxB,GAAE,MAEHC,cAAc/B,KAAKoB,aACnBpB,KAAKoB,YAAc,KAE1B,gCAED,WAAuC,IAAvBY,EAAuB,wDACnChC,KAAKsB,eAAiBtB,KAAKqB,WAC3B,IAAIY,EAAgBjC,KAAKkB,gBAAgBgB,MAAMC,cAAcC,OACzDC,EAAiBJ,EAAcK,OAAS,EAAIL,EAAgB,GAC7DI,GAAkBrC,KAAKsB,iBACtBtB,KAAKqB,WAAagB,EACfL,IAAehD,EAAAA,EAAAA,UAASgB,KAAKuC,SAAU,KAEjD,uBAED,WAAS,WACiB,IAAnBvC,KAAKqB,oBAhDgB,kCAiDpBmB,CAAiBxC,KAAKqB,YAAYoB,MAAK,SAACC,GACtB,IAAXA,GACC,EAAKnB,eAAeoB,UAAYD,EAChC,EAAKnB,eAAeqB,aAAa,cAAc,SAC/C,EAAKpB,eAAgB,IAErB,EAAKD,eAAeoB,UAAY,GAChC,EAAKpB,eAAeqB,aAAa,cAAc,QAC/C,EAAKpB,eAAgB,EAE5B,KAEDxB,KAAKuB,eAAeoB,UAAY,GAChC3C,KAAKuB,eAAeqB,aAAa,cAAc,QAC/C5C,KAAKwB,eAAgB,EAE5B,uFA7DCR,GAkEC,SAAS6B,EAAWC,GACvBA,EAASC,SAAQ,SAACC,GAEQ,IAAlBA,EAAKC,UACL,IAAIjC,EAAkBgC,EAE7B,GACJ","sources":["webpack://nationalspacecentre.web/./node_modules/debounce/index.js","webpack://nationalspacecentre.web/./wwwroot/app/src/js/collections-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 collectionsSearchURL = window.collectionsSearchEndpoint.toString() + (window.collectionsSearchEndpoint.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(collectionsSearchURL + searchString)).text();\r\n}\r\n\r\nclass CollectionsSearch {\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('.collections-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 CollectionsSearch(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","collectionsSearchURL","window","collectionsSearchEndpoint","toString","indexOf","searchString","fetch","text","CollectionsSearch","el","searchTextField","querySelector","searchWatch","searchText","prevSearchText","resultsWrapper","resultsActive","onfocus","watchSearchText","onblur","mode","setInterval","checkSearchText","clearInterval","triggerUpdate","getSearchText","value","toLowerCase","trim","workSearchText","length","update","getSearchResults","then","content","innerHTML","setAttribute","createFrom","wrappers","forEach","node","nodeType"],"sourceRoot":""}