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C5B,MAAO,CACHuB,KAAMW,EAAO1C,OAAS0C,EAAO,GAAGR,OAA1B,eAA2C1B,GACjDkC,OAAQA,EACRC,QAAS,QACTC,WAAY,QACZC,MAAO,EACPC,UAAW,CACPZ,OAAQ,SAACa,GAAD,OAAWA,EAAMC,YAAY,GAAGd,OAArB,kFACyBa,EAAMC,YAAY,GAAGd,OAD9C,4CAEfe,GACJ9C,WAAY,SAACS,GAAD,oLAE+CA,EAAKqB,MAFpD,wDAGFrB,EAAKoB,OAAL,aAAoBpB,EAAKoB,QAAW,GAHlC,yF,EA/ElC5C,G","sources":["webpack://umms-html/./FrontEndSrc/modules/macro/typeahead/typeahead.js"],"sourcesContent":["/* jQuery, Bloodhound */\r\n\r\n'use strict';\r\n\r\nimport '../../../js/vendor/typeaheadjs/dist/typeahead.jquery.js';\r\nimport Bloodhound from '../../../js/vendor/typeaheadjs/dist/bloodhound.min.js';\r\n\r\nclass Typeahead {\r\n    wrap;\r\n    bloodhoundArr;\r\n    ui;\r\n\r\n    constructor(options) {\r\n        if (options.wrap) {\r\n            this.wrap = options.wrap;\r\n        }\r\n\r\n        if (this.wrap) {\r\n            this.ui = {\r\n                typeaheadInputs: $('.js-typeahead-input'),\r\n                searchType: $('.js-typeahead-input-search-type')\r\n            };\r\n\r\n            this.bloodhoundArr = [];\r\n\r\n            window.addEventListener('load', () => this.implementTypeahead());\r\n\r\n            if (this.ui.searchType.length) {\r\n                $(this.wrap).bind('typeahead:select', (ev, suggestion) => {\r\n                    suggestion.type ?\r\n                        $(this.ui.searchType).val(suggestion.type) :\r\n                        $(this.ui.searchType).val('');\r\n                    this.wrap.submit();\r\n                });\r\n            }\r\n        }\r\n    }\r\n\r\n    implementTypeahead() {\r\n        this.ui.typeaheadInputs.each((index, input) => {\r\n            var thisInput = $(input),\r\n                jsonInDom = $('.' + thisInput.data('json-identifier')),\r\n                jsonArr = [];\r\n\r\n            if (jsonInDom.length) {\r\n                jsonInDom.each((i, el) => {\r\n                    jsonArr.push(JSON.parse($(el).html()));\r\n                });\r\n            }\r\n\r\n            // Implement Bloodhound\r\n            // Pushes each dataset into an array as a bloodhound object of suggestions\r\n            $(jsonArr).each((i, json) => {\r\n                this.bloodhoundArr.push(new Bloodhound({\r\n                    datumTokenizer: Bloodhound.tokenizers.obj.whitespace('name'),\r\n                    queryTokenizer: Bloodhound.tokenizers.whitespace,\r\n                    local: json.results.map(result => ({\r\n                        name: result.name + ' ' + result.helper,\r\n                        value: result.name,\r\n                        helper: result.helper,\r\n                        type: result.type,\r\n                        header: json.title,\r\n                    })),\r\n                }));\r\n            });\r\n\r\n            // Implement Typeahead\r\n            // \"apply\" is used because typeahead takes an argument list for its data sources (not an array)\r\n            // We don't know how many data sources there are, so \"apply\" converts\r\n            // the array of data sources into an argument list\r\n            thisInput.typeahead.apply(thisInput, [{\r\n                hint: true,\r\n                highlight: true,\r\n                minLength: 2,\r\n            }].concat(\r\n                this.bloodhoundArr.map((source, index) => {\r\n                    return {\r\n                        name: source.length ? source[0].header : `data_${index}`,\r\n                        source: source,\r\n                        display: 'value',\r\n                        displayKey: 'value',\r\n                        limit: 8,\r\n                        templates: {\r\n                            header: (query) => query.suggestions[0].header ? `\r\n                                <h3 class=\"twitter-typeahead__header\">${query.suggestions[0].header}</h3>\r\n                            ` : undefined,\r\n                            suggestion: (data) => `\r\n                                <div class=\"twitter-typeahead__suggestion\">\r\n                                    <span class=\"twitter-typeahead__suggestion-name\">${data.value}</span>\r\n                                    ${data.helper ? ` - ${data.helper}` : ''}\r\n                                </div>\r\n                            `\r\n                        }\r\n                    };\r\n                }\r\n            )));\r\n\r\n        });\r\n    }\r\n}\r\n\r\nexport default Typeahead;\r\n"],"names":["Typeahead","options","wrap","this","ui","typeaheadInputs","$","searchType","bloodhoundArr","window","addEventListener","implementTypeahead","length","bind","ev","suggestion","type","val","submit","each","index","input","thisInput","jsonInDom","data","jsonArr","i","el","push","JSON","parse","html","json","Bloodhound","datumTokenizer","tokenizers","obj","whitespace","queryTokenizer","local","results","map","result","name","helper","value","header","title","typeahead","apply","hint","highlight","minLength","concat","source","display","displayKey","limit","templates","query","suggestions","undefined"],"sourceRoot":""}