!function(n,t){"use strict";"undefined"!=typeof module&&module.exports?module.exports=t(require("jquery")):"function"==typeof define&&define.amd?define(["jquery"],function(n){return t(n)}):t(n.jQuery)}(this,function(n){"use strict";var t=function(i,r){this.$element=n(i);this.options=n.extend({},t.defaults,r);this.matcher=this.options.matcher||this.matcher;this.sorter=this.options.sorter||this.sorter;this.select=this.options.select||this.select;this.autoSelect="boolean"!=typeof this.options.autoSelect||this.options.autoSelect;this.highlighter=this.options.highlighter||this.highlighter;this.render=this.options.render||this.render;this.updater=this.options.updater||this.updater;this.displayText=this.options.displayText||this.displayText;this.itemLink=this.options.itemLink||this.itemLink;this.itemTitle=this.options.itemTitle||this.itemTitle;this.followLinkOnSelect=this.options.followLinkOnSelect||this.followLinkOnSelect;this.source=this.options.source;this.delay=this.options.delay;this.theme=this.options.theme&&this.options.themes&&this.options.themes[this.options.theme]||t.defaults.themes[t.defaults.theme];this.$menu=n(this.options.menu||this.theme.menu);this.$appendTo=this.options.appendTo?n(this.options.appendTo):null;this.fitToElement="boolean"==typeof this.options.fitToElement&&this.options.fitToElement;this.shown=!1;this.listen();this.showHintOnFocus=("boolean"==typeof this.options.showHintOnFocus||"all"===this.options.showHintOnFocus)&&this.options.showHintOnFocus;this.afterSelect=this.options.afterSelect;this.afterEmptySelect=this.options.afterEmptySelect;this.addItem=!1;this.value=this.$element.val()||this.$element.text();this.keyPressed=!1;this.focused=this.$element.is(":focus");this.changeInputOnSelect=this.options.changeInputOnSelect||this.changeInputOnSelect;this.changeInputOnMove=this.options.changeInputOnMove||this.changeInputOnMove;this.openLinkInNewTab=this.options.openLinkInNewTab||this.openLinkInNewTab;this.selectOnBlur=this.options.selectOnBlur||this.selectOnBlur;this.showCategoryHeader=this.options.showCategoryHeader||this.showCategoryHeader},i;t.prototype={constructor:t,setDefault:function(n){if(this.$element.data("active",n),this.autoSelect||n){var t=this.updater(n);t||(t="");this.$element.val(this.displayText(t)||t).text(this.displayText(t)||t).change();this.afterSelect(t)}return this.hide()},select:function(){var t=this.$menu.find(".active").data("value"),n;return(this.$element.data("active",t),this.autoSelect||t)?(n=this.updater(t),n||(n=""),this.changeInputOnSelect&&this.$element.val(this.displayText(n)||n).text(this.displayText(n)||n).change(),this.followLinkOnSelect&&this.itemLink(t)?(this.openLinkInNewTab?window.open(this.itemLink(t),"_blank"):document.location=this.itemLink(t),this.afterSelect(n)):this.followLinkOnSelect&&!this.itemLink(t)?this.afterEmptySelect(n):this.afterSelect(n)):this.afterEmptySelect(),this.hide()},updater:function(n){return n},setSource:function(n){this.source=n},show:function(){var t,i=n.extend({},this.$element.position(),{height:this.$element[0].offsetHeight}),e="function"==typeof this.options.scrollHeight?this.options.scrollHeight.call():this.options.scrollHeight,r,u,f;return(this.shown?t=this.$menu:this.$appendTo?(t=this.$menu.appendTo(this.$appendTo),this.hasSameParent=this.$appendTo.is(this.$element.parent())):(t=this.$menu.insertAfter(this.$element),this.hasSameParent=!0),this.hasSameParent)||(t.css("position","fixed"),r=this.$element.offset(),i.top=r.top,i.left=r.left),u=n(t).parent().hasClass("dropup")?"auto":i.top+i.height+e,f=n(t).hasClass("dropdown-menu-right")?"auto":i.left,t.css({top:u,left:f}).show(),!0===this.options.fitToElement&&t.css("width",this.$element.outerWidth()+"px"),this.shown=!0,this},hide:function(){return this.$menu.hide(),this.shown=!1,this},lookup:function(t){if(this.query=null!=t?t:this.$element.val(),this.query.length<this.options.minLength&&!this.options.showHintOnFocus)return this.shown?this.hide():this;var i=n.proxy(function(){n.isFunction(this.source)&&3===this.source.length?this.source(this.query,n.proxy(this.process,this),n.proxy(this.process,this)):n.isFunction(this.source)?this.source(this.query,n.proxy(this.process,this)):this.source&&this.process(this.source)},this);clearTimeout(this.lookupWorker);this.lookupWorker=setTimeout(i,this.delay)},process:function(t){var i=this;return t=n.grep(t,function(n){return i.matcher(n)}),(t=this.sorter(t)).length||this.options.addItem?(t.length>0?this.$element.data("active",t[0]):this.$element.data("active",null),"all"!=this.options.items&&(t=t.slice(0,this.options.items)),this.options.addItem&&t.push(this.options.addItem),this.render(t).show()):this.shown?this.hide():this},matcher:function(n){return~this.displayText(n).toLowerCase().indexOf(this.query.toLowerCase())},sorter:function(n){for(var i,t,r=[],u=[],f=[];t=n.shift();)i=this.displayText(t),i.toLowerCase().indexOf(this.query.toLowerCase())?~i.indexOf(this.query)?u.push(t):f.push(t):r.push(t);return r.concat(u,f)},highlighter:function(n){var u=this.query,o,e;if(""===u)return n;var t,i=n.match(/(>)([^<]*)(<)/g),r=[],f=[];if(i&&i.length)for(t=0;t<i.length;++t)i[t].length>2&&r.push(i[t]);else(r=[]).push(n);for(u=u.replace(/[\(\)\/\.\*\+\?\[\]]/g,function(n){return"\\"+n}),e=new RegExp(u,"g"),t=0;t<r.length;++t)(o=r[t].match(e))&&o.length>0&&f.push(r[t]);for(t=0;t<f.length;++t)n=n.replace(f[t],f[t].replace(e,"<strong>$&<\/strong>"));return n},render:function(t){var i=this,u=this,e=!1,f=[],r=i.options.separator;return n.each(t,function(n,i){n>0&&i[r]!==t[n-1][r]&&f.push({__type:"divider"});this.showCategoryHeader&&(!i[r]||0!==n&&i[r]===t[n-1][r]||f.push({__type:"category",name:i[r]}));f.push(i)}),t=n(f).map(function(t,r){if("category"==(r.__type||!1))return n(i.options.headerHtml||i.theme.headerHtml).text(r.name)[0];if("divider"==(r.__type||!1))return n(i.options.headerDivider||i.theme.headerDivider)[0];var f=u.displayText(r);return(t=n(i.options.item||i.theme.item).data("value",r)).find(i.options.itemContentSelector||i.theme.itemContentSelector).addBack(i.options.itemContentSelector||i.theme.itemContentSelector).html(i.highlighter(f,r)),i.options.followLinkOnSelect&&t.find("a").attr("href",u.itemLink(r)),t.find("a").attr("title",u.itemTitle(r)),f==u.$element.val()&&(t.addClass("active"),u.$element.data("active",r),e=!0),t[0]}),this.autoSelect&&!e&&(t.filter(":not(.dropdown-header)").first().addClass("active"),this.$element.data("active",t.first().data("value"))),this.$menu.html(t),this},displayText:function(n){return void 0!==n&&void 0!==n.name?n.name:n},itemLink:function(){return null},itemTitle:function(){return null},next:function(){var t=this.$menu.find(".active").removeClass("active").next(),i;for(t.length||(t=n(this.$menu.find(n(this.options.item||this.theme.item).prop("tagName"))[0]));t.hasClass("divider")||t.hasClass("dropdown-header");)t=t.next();t.addClass("active");i=this.updater(t.data("value"));this.changeInputOnMove&&this.$element.val(this.displayText(i)||i)},prev:function(){var t=this.$menu.find(".active").removeClass("active").prev(),i;for(t.length||(t=this.$menu.find(n(this.options.item||this.theme.item).prop("tagName")).last());t.hasClass("divider")||t.hasClass("dropdown-header");)t=t.prev();t.addClass("active");i=this.updater(t.data("value"));this.changeInputOnMove&&this.$element.val(this.displayText(i)||i)},listen:function(){this.$element.on("focus.bootstrap3Typeahead",n.proxy(this.focus,this)).on("blur.bootstrap3Typeahead",n.proxy(this.blur,this)).on("keypress.bootstrap3Typeahead",n.proxy(this.keypress,this)).on("propertychange.bootstrap3Typeahead input.bootstrap3Typeahead",n.proxy(this.input,this)).on("keyup.bootstrap3Typeahead",n.proxy(this.keyup,this));this.eventSupported("keydown")&&this.$element.on("keydown.bootstrap3Typeahead",n.proxy(this.keydown,this));var t=n(this.options.item||this.theme.item).prop("tagName");"ontouchstart"in document.documentElement?this.$menu.on("touchstart",t,n.proxy(this.touchstart,this)).on("touchend",t,n.proxy(this.click,this)):this.$menu.on("click",n.proxy(this.click,this)).on("mouseenter",t,n.proxy(this.mouseenter,this)).on("mouseleave",t,n.proxy(this.mouseleave,this)).on("mousedown",n.proxy(this.mousedown,this))},destroy:function(){this.$element.data("typeahead",null);this.$element.data("active",null);this.$element.unbind("focus.bootstrap3Typeahead").unbind("blur.bootstrap3Typeahead").unbind("keypress.bootstrap3Typeahead").unbind("propertychange.bootstrap3Typeahead input.bootstrap3Typeahead").unbind("keyup.bootstrap3Typeahead");this.eventSupported("keydown")&&this.$element.unbind("keydown.bootstrap3-typeahead");this.$menu.remove();this.destroyed=!0},eventSupported:function(n){var t=n in this.$element;return t||(this.$element.setAttribute(n,"return;"),t="function"==typeof this.$element[n]),t},move:function(n){if(this.shown)switch(n.keyCode){case 9:case 13:case 27:n.preventDefault();break;case 38:if(n.shiftKey)return;n.preventDefault();this.prev();break;case 40:if(n.shiftKey)return;n.preventDefault();this.next()}},keydown:function(t){17!==t.keyCode&&(this.keyPressed=!0,this.suppressKeyPressRepeat=~n.inArray(t.keyCode,[40,38,9,13,27]),this.shown||40!=t.keyCode?this.move(t):this.lookup())},keypress:function(n){this.suppressKeyPressRepeat||this.move(n)},input:function(){var n=this.$element.val()||this.$element.text();this.value!==n&&(this.value=n,this.lookup())},keyup:function(n){if(!this.destroyed)switch(n.keyCode){case 9:if(!this.shown||this.showHintOnFocus&&!this.keyPressed)return;this.select();break;case 13:if(!this.shown)return;this.select();break;case 27:if(!this.shown)return;this.hide()}},focus:function(){this.focused||(this.focused=!0,this.keyPressed=!1,this.options.showHintOnFocus&&!0!==this.skipShowHintOnFocus&&("all"===this.options.showHintOnFocus?this.lookup(""):this.lookup()));this.skipShowHintOnFocus&&(this.skipShowHintOnFocus=!1)},blur:function(){this.mousedover||this.mouseddown||!this.shown?this.mouseddown&&(this.skipShowHintOnFocus=!0,this.$element.focus(),this.mouseddown=!1):(this.selectOnBlur&&this.select(),this.hide(),this.focused=!1,this.keyPressed=!1)},click:function(n){n.preventDefault();this.skipShowHintOnFocus=!0;this.select();this.$element.focus();this.hide()},mouseenter:function(t){this.mousedover=!0;this.$menu.find(".active").removeClass("active");n(t.currentTarget).addClass("active")},mouseleave:function(){this.mousedover=!1;!this.focused&&this.shown&&this.hide()},mousedown:function(){this.mouseddown=!0;this.$menu.one("mouseup",function(){this.mouseddown=!1}.bind(this))},touchstart:function(t){t.preventDefault();this.$menu.find(".active").removeClass("active");n(t.currentTarget).addClass("active")},touchend:function(n){n.preventDefault();this.select();this.$element.focus()}};i=n.fn.typeahead;n.fn.typeahead=function(i){var r=arguments;return"string"==typeof i&&"getActive"==i?this.data("active"):this.each(function(){var f=n(this),u=f.data("typeahead"),e="object"==typeof i&&i;u||f.data("typeahead",u=new t(this,e));"string"==typeof i&&u[i]&&(r.length>1?u[i].apply(u,Array.prototype.slice.call(r,1)):u[i]())})};t.defaults={source:[],items:8,minLength:1,scrollHeight:0,autoSelect:!0,afterSelect:n.noop,afterEmptySelect:n.noop,addItem:!1,followLinkOnSelect:!1,delay:0,separator:"category",changeInputOnSelect:!0,changeInputOnMove:!0,openLinkInNewTab:!1,selectOnBlur:!0,showCategoryHeader:!0,theme:"bootstrap3",themes:{bootstrap3:{menu:'<ul class="typeahead dropdown-menu" role="listbox"><\/ul>',item:'<li><a class="dropdown-item" href="#" role="option"><\/a><\/li>',itemContentSelector:"a",headerHtml:'<li class="dropdown-header"><\/li>',headerDivider:'<li class="divider" role="separator"><\/li>'},bootstrap4:{menu:'<div class="typeahead dropdown-menu" role="listbox"><\/div>',item:'<button class="dropdown-item" role="option"><\/button>',itemContentSelector:".dropdown-item",headerHtml:'<h6 class="dropdown-header"><\/h6>',headerDivider:'<div class="dropdown-divider"><\/div>'}}};n.fn.typeahead.Constructor=t;n.fn.typeahead.noConflict=function(){return n.fn.typeahead=i,this};n(document).on("focus.typeahead.data-api",'[data-provide="typeahead"]',function(){var t=n(this);t.data("typeahead")||t.typeahead(t.data())})})