!function(t){var e;"function"==typeof define&&define.amd?define("jquery-typeahead",["jquery"],function(e){return t(e)}):"object"==typeof module&&module.exports?module.exports=(void 0===e&&(e="undefined"!=typeof window?require("jquery"):require("jquery")(void 0)),t(e)):t(jQuery)}(function(t){"use strict";function e(t,e){this.rawQuery=t.val()||"",this.query=t.val()||"",this.selector=t[0].selector,this.deferred=null,this.tmpSource={},this.source={},this.dynamicGroups=[],this.hasDynamicGroups=!1,this.generatedGroupCount=0,this.groupBy="group",this.groups=[],this.searchGroups=[],this.generateGroups=[],this.requestGroups=[],this.result=[],this.tmpResult={},this.groupTemplate="",this.resultHtml=null,this.resultCount=0,this.resultCountPerGroup={},this.options=e,this.node=t,this.namespace="."+this.helper.slugify.call(this,this.selector)+".typeahead",this.isContentEditable=void 0!==this.node.attr("contenteditable")&&"false"!==this.node.attr("contenteditable"),this.container=null,this.resultContainer=null,this.item=null,this.items=null,this.comparedItems=null,this.xhr={},this.hintIndex=null,this.filters={dropdown:{},dynamic:{}},this.dropdownFilter={static:[],dynamic:[]},this.dropdownFilterAll=null,this.isDropdownEvent=!1,this.requests={},this.backdrop={},this.hint={},this.label={},this.hasDragged=!1,this.focusOnly=!1,this.displayEmptyTemplate,this.__construct()}var i,s={input:null,minLength:2,maxLength:!(window.Typeahead={version:"2.11.0"}),maxItem:8,dynamic:!1,delay:300,order:null,offset:!1,hint:!1,accent:!1,highlight:!0,multiselect:null,group:!1,groupOrder:null,maxItemPerGroup:null,dropdownFilter:!1,dynamicFilter:null,backdrop:!1,backdropOnFocus:!1,cache:!1,ttl:36e5,compression:!1,searchOnFocus:!1,blurOnTab:!0,resultContainer:null,generateOnLoad:null,mustSelectItem:!1,href:null,display:["display"],template:null,templateValue:null,groupTemplate:null,correlativeTemplate:!1,emptyTemplate:!1,cancelButton:!0,loadingAnimation:!0,asyncResult:!1,filter:!0,matcher:null,source:null,callback:{onInit:null,onReady:null,onShowLayout:null,onHideLayout:null,onSearch:null,onResult:null,onLayoutBuiltBefore:null,onLayoutBuiltAfter:null,onNavigateBefore:null,onNavigateAfter:null,onEnter:null,onLeave:null,onClickBefore:null,onClickAfter:null,onDropdownFilter:null,onSendRequest:null,onReceiveRequest:null,onPopulateSource:null,onCacheSave:null,onSubmit:null,onCancel:null},selector:{container:"typeahead__container",result:"typeahead__result",list:"typeahead__list",group:"typeahead__group",item:"typeahead__item",empty:"typeahead__empty",display:"typeahead__display",query:"typeahead__query",filter:"typeahead__filter",filterButton:"typeahead__filter-button",dropdown:"typeahead__dropdown",dropdownItem:"typeahead__dropdown-item",labelContainer:"typeahead__label-container",label:"typeahead__label",button:"typeahead__button",backdrop:"typeahead__backdrop",hint:"typeahead__hint",cancelButton:"typeahead__cancel-button"},debug:!1},o={from:"ãà áäâẽèéëêìíïîõòóöôùúüûñç",to:"aaaaaeeeeeiiiiooooouuuunc"},n=~window.navigator.appVersion.indexOf("MSIE 9."),r=~window.navigator.appVersion.indexOf("MSIE 10"),a=!!~window.navigator.userAgent.indexOf("Trident")&&~window.navigator.userAgent.indexOf("rv:11");e.prototype={_validateCacheMethod:function(t){var e;if(!0===t)t="localStorage";else if("string"==typeof t&&!~["localStorage","sessionStorage"].indexOf(t))return!1;e=void 0!==window[t];try{window[t].setItem("typeahead","typeahead"),window[t].removeItem("typeahead")}catch(t){e=!1}return e&&t||!1},extendOptions:function(){if(this.options.cache=this._validateCacheMethod(this.options.cache),this.options.compression&&("object"==typeof LZString&&this.options.cache||(this.options.compression=!1)),this.options.maxLength&&!isNaN(this.options.maxLength)||(this.options.maxLength=1/0),void 0!==this.options.maxItem&&~[0,!1].indexOf(this.options.maxItem)&&(this.options.maxItem=1/0),this.options.maxItemPerGroup&&!/^\d+$/.test(this.options.maxItemPerGroup)&&(this.options.maxItemPerGroup=null),this.options.display&&!Array.isArray(this.options.display)&&(this.options.display=[this.options.display]),this.options.multiselect&&(this.items=[],this.comparedItems=[],"string"==typeof this.options.multiselect.matchOn&&(this.options.multiselect.matchOn=[this.options.multiselect.matchOn])),this.options.group&&(Array.isArray(this.options.group)||("string"==typeof this.options.group?this.options.group={key:this.options.group}:"boolean"==typeof this.options.group&&(this.options.group={key:"group"}),this.options.group.key=this.options.group.key||"group")),this.options.highlight&&!~["any",!0].indexOf(this.options.highlight)&&(this.options.highlight=!1),this.options.dropdownFilter&&this.options.dropdownFilter instanceof Object){Array.isArray(this.options.dropdownFilter)||(this.options.dropdownFilter=[this.options.dropdownFilter]);for(var e=0,i=this.options.dropdownFilter.length;ee.maxLength&&(e.minLength=e.maxLength),this.options.source[t]=e,this.options.source[t].dynamic&&this.dynamicGroups.push(t),e.cache=void 0!==e.cache?this._validateCacheMethod(e.cache):this.options.cache,e.compression&&("object"==typeof LZString&&e.cache||(e.compression=!1))}return this.hasDynamicGroups=this.options.dynamic||!!this.dynamicGroups.length,!0},init:function(){this.helper.executeCallback.call(this,this.options.callback.onInit,[this.node]),this.container=this.node.closest("."+this.options.selector.container)},delegateEvents:function(){var e=this,i=["focus"+this.namespace,"input"+this.namespace,"propertychange"+this.namespace,"keydown"+this.namespace,"keyup"+this.namespace,"search"+this.namespace,"generate"+this.namespace];t("html").on("touchmove",function(){e.hasDragged=!0}).on("touchstart",function(){e.hasDragged=!1}),this.node.closest("form").on("submit",function(t){if(!e.options.mustSelectItem||!e.helper.isEmpty(e.item))return e.options.backdropOnFocus||e.hideLayout(),e.options.callback.onSubmit?e.helper.executeCallback.call(e,e.options.callback.onSubmit,[e.node,this,e.item||e.items,t]):void 0;t.preventDefault()}).on("reset",function(){setTimeout(function(){e.node.trigger("input"+e.namespace),e.hideLayout()})});var s=!1;if(this.node.attr("placeholder")&&(r||a)){var o=!0;this.node.on("focusin focusout",function(){o=!(this.value||!this.placeholder)}),this.node.on("input",function(t){o&&(t.stopImmediatePropagation(),o=!1)})}this.node.off(this.namespace).on(i.join(" "),function(i,o){switch(i.type){case"generate":e.generateSource(Object.keys(e.options.source));break;case"focus":if(e.focusOnly){e.focusOnly=!1;break}e.options.backdropOnFocus&&(e.buildBackdropLayout(),e.showLayout()),e.options.searchOnFocus&&!e.item&&(e.deferred=t.Deferred(),e.assignQuery(),e.generateSource());break;case"keydown":8===i.keyCode&&e.options.multiselect&&e.options.multiselect.cancelOnBackspace&&""===e.query&&e.items.length?e.cancelMultiselectItem(e.items.length-1,null,i):i.keyCode&&~[9,13,27,38,39,40].indexOf(i.keyCode)&&(s=!0,e.navigate(i));break;case"keyup":n&&e.node[0].value.replace(/^\s+/,"").toString().length=this.options.source[t].minLength&&this.query.length<=this.options.source[t].maxLength){if(this.filters.dropdown&&"group"===this.filters.dropdown.key&&this.filters.dropdown.value!==t)continue;if(this.searchGroups.push(t),!this.options.source[t].dynamic&&this.source[t])continue;this.generateGroups.push(t)}},generateSource:function(e){if(this.filterGenerateSource(),this.generatedGroupCount=0,Array.isArray(e)&&e.length)this.generateGroups=e;else if(!this.generateGroups.length)return void this.node.trigger("search"+this.namespace);if(this.requestGroups=[],this.options.loadingAnimation&&this.container.addClass("loading"),!this.helper.isEmpty(this.xhr)){for(var i in this.xhr)this.xhr.hasOwnProperty(i)&&this.xhr[i].abort();this.xhr={}}for(var s,o,n,r,a,l,h,c=this,p=(i=0,this.generateGroups.length);i(new Date).getTime()?(this.populateSource(l.data,s),h=!0):window[r].removeItem("TYPEAHEAD_"+this.selector+":"+s)}catch(e){}if(h)continue}!n.data||n.ajax?n.ajax&&(this.requests[s]||(this.requests[s]=this.generateRequestObject(s)),this.requestGroups.push(s)):"function"==typeof n.data?(o=n.data.call(this),Array.isArray(o)?c.populateSource(o,s):"function"==typeof o.promise&&function(e){t.when(o).then(function(t){t&&Array.isArray(t)&&c.populateSource(t,e)})}(s)):this.populateSource(t.extend(!0,[],n.data),s)}return this.requestGroups.length&&this.handleRequests(),this.options.asyncResult&&this.searchGroups.length!==this.generateGroups&&this.node.trigger("search"+this.namespace),!!this.generateGroups.length},generateRequestObject:function(t){var e=this,i=this.options.source[t],s={request:{url:i.ajax.url||null,dataType:"json",beforeSend:function(s,o){e.xhr[t]=s;var n=e.requests[t].callback.beforeSend||i.ajax.beforeSend;"function"==typeof n&&n.apply(null,arguments)}},callback:{beforeSend:null,done:null,fail:null,then:null,always:null},extra:{path:i.ajax.path||null,group:t},validForGroup:[t]};if("function"!=typeof i.ajax&&(i.ajax instanceof Object&&(s=this.extendXhrObject(s,i.ajax)),1/g," ").replace(/\s{2,}/," ").trim();for(h=0,c=e.length;h").html(y.replace(/\{\{([\w\-\.]+)(?:\|(\w+))?}}/g,function(t,i){return o.helper.namespace.call(o,i,e[h],"get","")}).trim()).text();n.display?~n.display.indexOf("compiled")||n.display.unshift("compiled"):~this.options.display.indexOf("compiled")||this.options.display.unshift("compiled")}}this.options.callback.onPopulateSource&&(e=this.helper.executeCallback.call(this,this.options.callback.onPopulateSource,[this.node,e,i,s])),this.tmpSource[i]=Array.isArray(e)&&e||[];var v=this.options.source[i].cache,b=this.options.source[i].compression,k=this.options.source[i].ttl||this.options.ttl;if(v&&!window[v].getItem("TYPEAHEAD_"+this.selector+":"+i)){this.options.callback.onCacheSave&&(e=this.helper.executeCallback.call(this,this.options.callback.onCacheSave,[this.node,e,i,s]));var w=JSON.stringify({data:e,ttl:(new Date).getTime()+k});b&&(w=LZString.compressToUTF16(w)),window[v].setItem("TYPEAHEAD_"+this.selector+":"+i,w)}this.incrementGeneratedGroup(i)},incrementGeneratedGroup:function(t){if(this.generatedGroupCount++,this.generatedGroupCount===this.generateGroups.length||this.options.asyncResult){this.xhr&&this.xhr[t]&&delete this.xhr[t];for(var e=0,i=this.generateGroups.length;e=this.query.length&&i.filter('[data-index="'+this.hintIndex+'"]').find("a:first")[0].click()}},getTemplateValue:function(t){if(t){var e=t.group&&this.options.source[t.group].templateValue||this.options.templateValue;if("function"==typeof e&&(e=e.call(this)),!e)return this.helper.namespace.call(this,t.matchedKey,t).toString();var i=this;return e.replace(/\{\{([\w\-.]+)}}/gi,function(e,s){return i.helper.namespace.call(i,s,t,"get","")})}},clearActiveItem:function(){this.resultContainer.find("."+this.options.selector.item).removeClass("active")},addActiveItem:function(t){t.addClass("active")},searchResult:function(){this.resetLayout(),!1!==this.helper.executeCallback.call(this,this.options.callback.onSearch,[this.node,this.query])&&(!this.searchGroups.length||this.options.multiselect&&this.options.multiselect.limit&&this.items.length>=this.options.multiselect.limit||this.searchResultData(),this.helper.executeCallback.call(this,this.options.callback.onResult,[this.node,this.query,this.result,this.resultCount,this.resultCountPerGroup]),this.isDropdownEvent&&(this.helper.executeCallback.call(this,this.options.callback.onDropdownFilter,[this.node,this.query,this.filters.dropdown,this.result]),this.isDropdownEvent=!1))},searchResultData:function(){var e,i,s,o,n,r,a,l,h,c,p,u=this.groupBy,d=null,f=this.query.toLowerCase(),m=this.options.maxItem,g=this.options.maxItemPerGroup,y=this.filters.dynamic&&!this.helper.isEmpty(this.filters.dynamic),v="function"==typeof this.options.matcher&&this.options.matcher;this.options.accent&&(f=this.helper.removeAccent.call(this,f));for(var b=0,k=this.searchGroups.length;b=m)||this.options.callback.onResult);w++)if((!y||this.dynamicFilter.validate.apply(this,[this.source[L][w]]))&&null!==(e=this.source[L][w])&&"boolean"!=typeof e&&(!this.options.multiselect||this.isMultiselectUniqueData(e))&&(!this.filters.dropdown||(e[this.filters.dropdown.key]||"").toLowerCase()===(this.filters.dropdown.value||"").toLowerCase())){if((d="group"===u?L:e[u]?e[u]:e.group)&&!this.tmpResult[d]&&(this.tmpResult[d]=[],this.resultCountPerGroup[d]=0),g&&"group"===u&&this.tmpResult[d].length>=g&&!this.options.callback.onResult)break;for(var C=0,q=(F=this.options.source[L].display||this.options.display).length;C=g)break;this.tmpResult[d].push(t.extend(!0,{matchedKey:F[C]},e)),this.resultItemCount++}break}if(!this.options.callback.onResult){if(this.resultItemCount>=m)break;if(g&&this.tmpResult[d].length>=g&&"group"===u)break}}if(this.options.order){var S,F=[];for(var L in this.tmpResult)if(this.tmpResult.hasOwnProperty(L)){for(b=0,k=this.tmpResult[L].length;b",{class:this.options.selector.result}),this.container.append(this.resultContainer)),!this.result.length&&this.generatedGroupCount===this.generateGroups.length)if(this.options.multiselect&&this.options.multiselect.limit&&this.items.length>=this.options.multiselect.limit)e=this.options.multiselect.limitTemplate?"function"==typeof this.options.multiselect.limitTemplate?this.options.multiselect.limitTemplate.call(this,this.query):this.options.multiselect.limitTemplate.replace(/\{\{query}}/gi,t("
").text(this.helper.cleanStringFromScript(this.query)).html()):"Can't select more than "+this.items.length+" items.";else{if(!this.options.emptyTemplate||""===this.query)return;e="function"==typeof this.options.emptyTemplate?this.options.emptyTemplate.call(this,this.query):this.options.emptyTemplate.replace(/\{\{query}}/gi,t("
").text(this.helper.cleanStringFromScript(this.query)).html())}this.displayEmptyTemplate=!!e;var i=this.query.toLowerCase();this.options.accent&&(i=this.helper.removeAccent.call(this,i));var s=this,o=this.groupTemplate||"
    ",n=!1;this.groupTemplate?o=t(o.replace(/<([^>]+)>\{\{(.+?)}}<\/[^>]+>/g,function(t,i,o,r,a){var l="",h="group"===o?s.groups:[o];if(!s.result.length)return!0===n?"":(n=!0,"<"+i+' class="'+s.options.selector.empty+'">'+e+"");for(var c=0,p=h.length;c
      ";return l})):(o=t(o),this.result.length||o.append(e instanceof t?e:'
    • '+e+"
    • ")),o.addClass(this.options.selector.list+(this.helper.isEmpty(this.result)?" empty":""));for(var r,a,l,h,c,p,u,d,f,m,g,y,v,b=this.groupTemplate&&this.result.length&&s.groups||[],k=0,w=this.result.length;k",{class:s.options.selector.group,html:t("",{href:"javascript:;",html:a||r,tabindex:-1}),"data-search-group":r}))),this.groupTemplate&&b.length&&~(g=b.indexOf(r||l.group))&&b.splice(g,1),c=t("
    • ",{class:s.options.selector.item+" "+s.options.selector.group+"-"+this.helper.slugify.call(this,r),disabled:!!l.disabled,"data-group":r,"data-index":k,html:t("",{href:h&&!l.disabled?(y=h,v=l,v.href=s.generateHref.call(s,y,v)):"javascript:;",html:function(){if(p=l.group&&s.options.source[l.group].template||s.options.template)"function"==typeof p&&(p=p.call(s,s.query,l)),u=p.replace(/\{\{([^\|}]+)(?:\|([^}]+))*}}/gi,function(t,e,o){var n=s.helper.cleanStringFromScript(String(s.helper.namespace.call(s,e,l,"get","")));return~(o=o&&o.split("|")||[]).indexOf("slugify")&&(n=s.helper.slugify.call(s,n)),~o.indexOf("raw")||!0===s.options.highlight&&i&&~f.indexOf(e)&&(n=s.helper.highlight.call(s,n,i.split(" "),s.options.accent)),n});else{for(var e=0,o=f.length;e'+s.helper.cleanStringFromScript(String(d.join(" ")))+""}(!0===s.options.highlight&&i&&!p||"any"===s.options.highlight)&&(u=s.helper.highlight.call(s,u,i.split(" "),s.options.accent)),t(this).append(u)}})}),function(e,i,o){o.on("click",function(e,o){i.disabled?e.preventDefault():(o&&"object"==typeof o&&(e.originalEvent=o),s.options.mustSelectItem&&s.helper.isEmpty(i)?e.preventDefault():(s.options.multiselect||(s.item=i),!1!==s.helper.executeCallback.call(s,s.options.callback.onClickBefore,[s.node,t(this),i,e])&&(e.originalEvent&&e.originalEvent.defaultPrevented||e.isDefaultPrevented()||(s.options.multiselect?(s.query=s.rawQuery="",s.addMultiselectItemLayout(i)):(s.focusOnly=!0,s.query=s.rawQuery=s.getTemplateValue.call(s,i),s.isContentEditable&&(s.node.text(s.query),s.helper.setCaretAtEnd(s.node[0]))),s.hideLayout(),s.node.val(s.query).focus(),s.options.cancelButton&&s.toggleCancelButtonVisibility(),s.helper.executeCallback.call(s,s.options.callback.onClickAfter,[s.node,t(this),i,e])))))}),o.on("mouseenter",function(e){i.disabled||(s.clearActiveItem(),s.addActiveItem(t(this))),s.helper.executeCallback.call(s,s.options.callback.onEnter,[s.node,t(this),i,e])}),o.on("mouseleave",function(e){i.disabled||s.clearActiveItem(),s.helper.executeCallback.call(s,s.options.callback.onLeave,[s.node,t(this),i,e])})}(0,l,c),(this.groupTemplate?o.find('[data-group-template="'+r+'"] ul'):o).append(c);if(this.result.length&&b.length)for(k=0,w=b.length;k",{class:this.options.selector.backdrop,css:this.backdrop.css}).insertAfter(this.container)),this.container.addClass("backdrop").css({"z-index":this.backdrop.css["z-index"]+1,position:"relative"}))},buildHintLayout:function(e){if(this.options.hint)if(this.node[0].scrollWidth>Math.ceil(this.node.innerWidth()))this.hint.container&&this.hint.container.val("");else{var i=this,s="",o=(e=e||this.result,this.query.toLowerCase());if(this.options.accent&&(o=this.helper.removeAccent.call(this,o)),this.hintIndex=null,this.searchGroups.length){if(this.hint.container||(this.hint.css=t.extend({"border-color":"transparent",position:"absolute",top:0,display:"inline","z-index":-1,float:"none",color:"silver","box-shadow":"none",cursor:"default","-webkit-user-select":"none","-moz-user-select":"none","-ms-user-select":"none","user-select":"none"},this.options.hint),this.hint.container=t("<"+this.node[0].nodeName+"/>",{type:this.node.attr("type"),class:this.node.attr("class"),readonly:!0,unselectable:"on","aria-hidden":"true",tabindex:-1,click:function(){i.node.focus()}}).addClass(this.options.selector.hint).css(this.hint.css).insertAfter(this.node),this.node.parent().css({position:"relative"})),this.hint.container.css("color",this.hint.css.color),o)for(var n,r,a,l=0,h=e.length;l",{class:this.options.selector.filter,html:function(){t(this).append(t("