/*! * jQuery Typeahead * Copyright (C) 2022 RunningCoder.org * Licensed under the MIT license * * @author Tom Bertrand * @version 2.11.2 (2022-9-16) * @link http://www.runningcoder.org/jquerytypeahead/ */ !function(t){var e;"function"==typeof define&&define.amd?define("jquery-typeahead",["jquery"],t):"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(L){"use strict";function r(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.2"}),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."),a=~window.navigator.appVersion.indexOf("MSIE 10"),l=!!~window.navigator.userAgent.indexOf("Trident")&&~window.navigator.userAgent.indexOf("rv:11"),e=(r.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 t=0,e=this.options.dropdownFilter.length;te.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,i=this,t=["focus"+this.namespace,"input"+this.namespace,"propertychange"+this.namespace,"keydown"+this.namespace,"keyup"+this.namespace,"search"+this.namespace,"generate"+this.namespace],s=(L("html").on("touchmove",function(){i.hasDragged=!0}).on("touchstart",function(){i.hasDragged=!1}),this.node.closest("form").on("submit",function(t){if(!i.options.mustSelectItem||!i.helper.isEmpty(i.item))return i.options.backdropOnFocus||i.hideLayout(),i.options.callback.onSubmit?i.helper.executeCallback.call(i,i.options.callback.onSubmit,[i.node,this,i.item||i.items,t]):void 0;t.preventDefault()}).on("reset",function(){setTimeout(function(){i.node.trigger("input"+i.namespace),i.hideLayout()})}),!1);this.node.attr("placeholder")&&(a||l)&&(e=!0,this.node.on("focusin focusout",function(){e=!(this.value||!this.placeholder)}),this.node.on("input",function(t){e&&(t.stopImmediatePropagation(),e=!1)})),this.node.off(this.namespace).on(t.join(" "),function(t,e){switch(t.type){case"generate":i.generateSource(Object.keys(i.options.source));break;case"focus":i.focusOnly?i.focusOnly=!1:(i.options.backdropOnFocus&&(i.buildBackdropLayout(),i.showLayout()),i.options.searchOnFocus&&!i.item&&(i.deferred=L.Deferred(),i.assignQuery(),i.generateSource()));break;case"keydown":8===t.keyCode&&i.options.multiselect&&i.options.multiselect.cancelOnBackspace&&""===i.query&&i.items.length?i.cancelMultiselectItem(i.items.length-1,null,t):t.keyCode&&~[9,13,27,38,39,40].indexOf(t.keyCode)&&(s=!0,i.navigate(t));break;case"keyup":n&&i.node[0].value.replace(/^\s+/,"").toString().length=this.options.source[t].minLength&&this.query.length<=this.options.source[t].maxLength&&(this.filters.dropdown&&"group"===this.filters.dropdown.key&&this.filters.dropdown.value!==t||(this.searchGroups.push(t),!this.options.source[t].dynamic&&this.source[t]||this.generateGroups.push(t)))},generateSource:function(t){if(this.filterGenerateSource(),this.generatedGroupCount=0,Array.isArray(t)&&t.length)this.generateGroups=t;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 e in this.xhr)this.xhr.hasOwnProperty(e)&&this.xhr[e].abort();this.xhr={}}for(var i,s,o,n,r,a,l=this,e=0,h=this.generateGroups.length;e(new Date).getTime()?(this.populateSource(r.data,i),a=!0):window[n].removeItem("TYPEAHEAD_"+this.selector+":"+i)}catch(t){}if(a)continue}o.data&&!o.ajax?"function"==typeof o.data?(s=o.data.call(this),Array.isArray(s)?l.populateSource(s,i):"function"==typeof s.promise&&function(e){L.when(s).then(function(t){t&&Array.isArray(t)&&l.populateSource(t,e)})}(i)):this.populateSource(L.extend(!0,[],o.data),i):o.ajax&&(this.requests[i]||(this.requests[i]=this.generateRequestObject(i)),this.requestGroups.push(i))}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(i){var s=this,o=this.options.source[i],t={request:{url:o.ajax.url||null,dataType:"json",beforeSend:function(t,e){s.xhr[i]=t;t=s.requests[i].callback.beforeSend||o.ajax.beforeSend;"function"==typeof t&&t.apply(null,arguments)}},callback:{beforeSend:null,done:null,fail:null,then:null,always:null},extra:{path:o.ajax.path||null,group:i},validForGroup:[i]};if("function"!=typeof o.ajax&&(o.ajax instanceof Object&&(t=this.extendXhrObject(t,o.ajax)),1/g," ").replace(/\s{2,}/," ").trim();for(l=0,h=i.length;l").html(m.replace(/\{\{([\w\-\.]+)(?:\|(\w+))?}}/g,function(t,e){return s.helper.namespace.call(s,e,i[l],"get","")}).trim()).text();o.display?~o.display.indexOf("compiled")||o.display.unshift("compiled"):~this.options.display.indexOf("compiled")||this.options.display.unshift("compiled")}}this.options.callback.onPopulateSource&&(i=this.helper.executeCallback.call(this,this.options.callback.onPopulateSource,[this.node,i,t,e])),this.tmpSource[t]=Array.isArray(i)&&i||[];var n=this.options.source[t].cache,o=this.options.source[t].compression,g=this.options.source[t].ttl||this.options.ttl;n&&!window[n].getItem("TYPEAHEAD_"+this.selector+":"+t)&&(this.options.callback.onCacheSave&&(i=this.helper.executeCallback.call(this,this.options.callback.onCacheSave,[this.node,i,t,e])),e=JSON.stringify({data:i,ttl:(new Date).getTime()+g}),o&&(e=LZString.compressToUTF16(e)),window[n].setItem("TYPEAHEAD_"+this.selector+":"+t,e)),this.incrementGeneratedGroup(t)},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&&e.filter('[data-index="'+this.hintIndex+'"]').find("a:first")[0].click():(9===t.keyCode?this.options.blurOnTab?this.hideLayout():0=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 t,e,i,s,o,n,r,a=this.groupBy,l=this.query.toLowerCase(),h=this.options.maxItem,c=this.options.maxItemPerGroup,p=this.filters.dynamic&&!this.helper.isEmpty(this.filters.dynamic),u="function"==typeof this.options.matcher&&this.options.matcher;this.options.accent&&(l=this.helper.removeAccent.call(this,l));for(var d=0,f=this.searchGroups.length;d=h)||this.options.callback.onResult);m++)if((!p||this.dynamicFilter.validate.apply(this,[this.source[A][m]]))&&null!==(e=this.source[A][m])&&"boolean"!=typeof e&&(!this.options.multiselect||this.isMultiselectUniqueData(e))&&(!this.filters.dropdown||(e[this.filters.dropdown.key]||"").toLowerCase()===(this.filters.dropdown.value||"").toLowerCase())){if((t="group"===a?A:e[a]||e.group)&&!this.tmpResult[t]&&(this.tmpResult[t]=[],this.resultCountPerGroup[t]=0),c&&"group"===a&&this.tmpResult[t].length>=c&&!this.options.callback.onResult)break;for(var y=0,b=(O=this.options.source[A].display||this.options.display).length;y=c)break;this.tmpResult[t].push(L.extend(!0,{matchedKey:O[y]},e)),this.resultItemCount++}break}if(!this.options.callback.onResult){if(this.resultItemCount>=h)break;if(c&&this.tmpResult[t].length>=c&&"group"===a)break}}if(this.options.order){var q,A,O=[];for(A in this.tmpResult)if(this.tmpResult.hasOwnProperty(A)){for(d=0,f=this.tmpResult[A].length;d",{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)h=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,L("
").text(this.helper.cleanStringFromScript(this.query)).html()):"Can't select more than "+this.items.length+" items.";else{if(!this.options.emptyTemplate||""===this.query)return;h="function"==typeof this.options.emptyTemplate?this.options.emptyTemplate.call(this,this.query):this.options.emptyTemplate.replace(/\{\{query}}/gi,L("
").text(this.helper.cleanStringFromScript(this.query)).html())}this.displayEmptyTemplate=!!h;var o=this.query.toLowerCase(),c=(this.options.accent&&(o=this.helper.removeAccent.call(this,o)),this),t=this.groupTemplate||"
    ",p=!1;this.groupTemplate?t=L(t.replace(/<([^>]+)>\{\{(.+?)}}<\/[^>]+>/g,function(t,e,i,s,o){var n="",r="group"===i?c.groups:[i];if(!c.result.length)return!0===p?"":(p=!0,"<"+e+' class="'+c.options.selector.empty+'">'+h+"");for(var a=0,l=r.length;a
      ";return n})):(t=L(t),this.result.length||t.append(h instanceof L?h:'
    • '+h+"
    • ")),t.addClass(this.options.selector.list+(this.helper.isEmpty(this.result)?" empty":""));for(var e,i,n,s,r,a,l,u,d,f,m=this.groupTemplate&&this.result.length&&c.groups||[],g=0,y=this.result.length;g",{class:c.options.selector.group,html:L("",{href:"javascript:;",html:i||e,tabindex:-1}),"data-search-group":e}))),this.groupTemplate&&m.length&&~(f=m.indexOf(e||n.group))&&m.splice(f,1),f=L("
    • ",{class:c.options.selector.item+" "+c.options.selector.group+"-"+this.helper.slugify.call(this,e),disabled:!!n.disabled,"data-group":e,"data-index":g,html:L("",{href:s&&!n.disabled?n.href=c.generateHref.call(c,s,n):"javascript:;",html:function(){if(r=n.group&&c.options.source[n.group].template||c.options.template)"function"==typeof r&&(r=r.call(c,c.query,n)),a=r.replace(/\{\{([^\|}]+)(?:\|([^}]+))*}}/gi,function(t,e,i){var s=c.helper.cleanStringFromScript(String(c.helper.namespace.call(c,e,n,"get","")));return~(i=i&&i.split("|")||[]).indexOf("slugify")&&(s=c.helper.slugify.call(c,s)),~i.indexOf("raw")||!0===c.options.highlight&&o&&~u.indexOf(e)&&(s=c.helper.highlight.call(c,s,o.split(" "),c.options.accent)),s});else{for(var t=0,e=u.length;t'+c.helper.cleanStringFromScript(String(l.join(" ")))+""}(!0===c.options.highlight&&o&&!r||"any"===c.options.highlight)&&(a=c.helper.highlight.call(c,a,o.split(" "),c.options.accent)),L(this).append(a)}})}),function(i,t){t.on("click",function(t,e){i.disabled||(e&&"object"==typeof e&&(t.originalEvent=e),c.options.mustSelectItem&&c.helper.isEmpty(i))?t.preventDefault():(c.options.multiselect||(c.item=i),!1===c.helper.executeCallback.call(c,c.options.callback.onClickBefore,[c.node,L(this),i,t])||t.originalEvent&&t.originalEvent.defaultPrevented||t.isDefaultPrevented()||(c.options.multiselect?(c.query=c.rawQuery="",c.addMultiselectItemLayout(i)):(c.focusOnly=!0,c.query=c.rawQuery=c.getTemplateValue.call(c,i),c.isContentEditable&&(c.node.text(c.query),c.helper.setCaretAtEnd(c.node[0]))),c.hideLayout(),c.node.val(c.query).focus(),c.options.cancelButton&&c.toggleCancelButtonVisibility(),c.helper.executeCallback.call(c,c.options.callback.onClickAfter,[c.node,L(this),i,t])))}),t.on("mouseenter",function(t){i.disabled||(c.clearActiveItem(),c.addActiveItem(L(this))),c.helper.executeCallback.call(c,c.options.callback.onEnter,[c.node,L(this),i,t])}),t.on("mouseleave",function(t){i.disabled||c.clearActiveItem(),c.helper.executeCallback.call(c,c.options.callback.onLeave,[c.node,L(this),i,t])})}(n,f),(this.groupTemplate?t.find('[data-group-template="'+e+'"] ul'):t).append(f);if(this.result.length&&m.length)for(g=0,y=m.length;g",{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(t){if(this.options.hint)if(this.node[0].scrollWidth>Math.ceil(this.node.innerWidth()))this.hint.container&&this.hint.container.val("");else{var e=this,i="",t=t||this.result,s=this.query.toLowerCase();if(this.options.accent&&(s=this.helper.removeAccent.call(this,s)),this.hintIndex=null,this.searchGroups.length){if(this.hint.container||(this.hint.css=L.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=L("<"+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(){e.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),s)for(var o,n=0,r=t.length;n",{class:(i=this).options.selector.filter,html:function(){L(this).append(L("