!function(a){"use strict";a.fn.autocomplete=function(b){var c;arguments.length>1?(c=b,b=arguments[1],b.url=c):"string"==typeof b&&(c=b,b={url:c});var d=a.extend({},a.fn.autocomplete.defaults,b);return this.each(function(){var b=a(this);b.data("autocompleter",new a.Autocompleter(b,a.meta?a.extend({},d,b.data()):d))})},a.fn.autocomplete.defaults={inputClass:"acInput",loadingClass:"acLoading",resultsClass:"acResults",selectClass:"acSelect",queryParamName:"q",extraParams:{},remoteDataType:!1,lineSeparator:"\n",cellSeparator:"|",minChars:2,maxItemsToShow:10,delay:400,useCache:!0,maxCacheLength:10,matchSubset:!0,matchCase:!1,matchInside:!0,mustMatch:!1,selectFirst:!1,selectOnly:!1,showResult:null,preventDefaultReturn:1,preventDefaultTab:0,autoFill:!1,filterResults:!0,filter:!0,sortResults:!0,sortFunction:null,onItemSelect:null,onNoMatch:null,onFinish:null,matchStringConverter:null,beforeUseConverter:null,autoWidth:"min-width",useDelimiter:!1,delimiterChar:",",delimiterKeyCode:188,processData:null,onError:null,enabled:!0};var b=function(b){var c,d,e=typeof b;return"string"===e?(c=b,d={}):a.isArray(b)?(c=b[0],d=b.slice(1)):"object"===e&&(c=b.value,d=b.data),c=String(c),"object"!=typeof d&&(d={}),{value:c,data:d}},c=function(a,b,c){var d=parseInt(a,10);return c=c||{},(isNaN(d)||c.min&&db?1:b>a?-1:0},g=function(a,b,c){var d,e,f,g,h,i,j=[];for(i=String(a).replace("\r\n","\n").split(b),d=0;d").hide().addClass(this.options.resultsClass).css({position:"absolute"}),a("body").append(this.dom.$results),b.keydown(function(a){switch(e.lastKeyPressed_=a.keyCode,e.lastKeyPressed_){case e.options.delimiterKeyCode:e.options.useDelimiter&&e.active_&&e.selectCurrent();break;case 35:case 36:case 16:case 17:case 18:case 37:case 39:break;case 38:return a.preventDefault(),e.active_?e.focusPrev():e.activate(),!1;case 40:return a.preventDefault(),e.active_?e.focusNext():e.activate(),!1;case 9:if(e.active_&&(e.selectCurrent(),e.options.preventDefaultTab))return a.preventDefault(),!1;if(2===e.options.preventDefaultTab)return a.preventDefault(),!1;break;case 13:if(e.active_&&(e.selectCurrent(),e.options.preventDefaultReturn))return a.preventDefault(),!1;if(2===e.options.preventDefaultReturn)return a.preventDefault(),!1;break;case 27:if(e.active_)return a.preventDefault(),e.deactivate(!0),!1;break;default:e.activate()}}),b.on("paste",function(){e.activate()});var f=function(){e.deactivate(!0)};b.blur(function(){e.finishOnBlur_&&(e.finishTimeout_=setTimeout(f,200))}),b.parents("form").on("submit",f)},a.Autocompleter.prototype.position=function(){var b=this.dom.$elem.offset(),c=this.dom.$results.outerHeight(),d=a(window).outerHeight(),e=b.top+this.dom.$elem.outerHeight(),f=e+c,g={top:e,left:b.left};if(f>d){var h=b.top-c;h>=0&&(g.top=h)}this.dom.$results.css(g)},a.Autocompleter.prototype.cacheRead=function(a){var b,c,d,e,f;if(this.options.useCache)for(a=String(a),b=a.length,c=this.options.matchSubset?1:b;b>=c;){for(e=this.options.matchInside?b-c:0,f=0;e>=f;){if(d=a.substr(0,c),void 0!==this.cacheData_[d])return this.cacheData_[d];f++}c++}return!1},a.Autocompleter.prototype.cacheWrite=function(a,b){return this.options.useCache?(this.cacheLength_>=this.options.maxCacheLength&&this.cacheFlush(),a=String(a),void 0!==this.cacheData_[a]&&this.cacheLength_++,this.cacheData_[a]=b,this.cacheData_[a]):!1},a.Autocompleter.prototype.cacheFlush=function(){this.cacheData_={},this.cacheLength_=0},a.Autocompleter.prototype.callHook=function(b,c){var d=this.options[b];return d&&a.isFunction(d)?d(c,this):!1},a.Autocompleter.prototype.activate=function(){if(this.options.enabled){var a=this;this.keyTimeout_&&clearTimeout(this.keyTimeout_),this.keyTimeout_=setTimeout(function(){a.activateNow()},this.options.delay)}},a.Autocompleter.prototype.activateNow=function(){var a=this.beforeUseConverter(this.dom.$elem.val());a!==this.lastProcessedValue_&&a!==this.lastSelectedValue_&&this.fetchData(a)},a.Autocompleter.prototype.fetchData=function(a){var b=this,c=function(a,c){b.options.processData&&(a=b.options.processData(a)),b.showResults(b.filterResults(a,c),c)};this.lastProcessedValue_=a,a.length-1:0===e}return!0},a.Autocompleter.prototype.filterResult=function(b,c){return this.options.filter===!1?!0:a.isFunction(this.options.filter)?this.options.filter(b,c):this.defaultFilter(b,c)},a.Autocompleter.prototype.filterResults=function(a,c){var d,e,f=[];for(d=0;d0&&this.options.maxItemsToShow");return d.html(this.showResult(b.value,b.data)),d.data({value:b.value,data:b.data}).click(function(){c.selectItem(d)}).mousedown(c.disableFinishOnBlur).mouseup(c.enableFinishOnBlur),d},a.Autocompleter.prototype.getItems=function(){return a(">ul>li",this.dom.$results)},a.Autocompleter.prototype.showResults=function(b,c){var d,e,f,g,h=b.length,i=this,j=a("
    "),k=!1,l=!1;if(h){for(d=0;h>d;d++)e=b[d],f=this.createItemFromResult(e),j.append(f),k===!1&&(k=String(e.value),l=f,f.addClass(this.options.firstItemClass)),d===h-1&&f.addClass(this.options.lastItemClass);this.dom.$results.html(j).show(),this.position(),this.options.autoWidth&&(g=this.dom.$elem.outerWidth()-this.dom.$results.outerWidth()+this.dom.$results.width(),this.dom.$results.css(this.options.autoWidth,g)),this.getItems().hover(function(){i.focusItem(this)},function(){}),(this.autoFill(k,c)||this.options.selectFirst||this.options.selectOnly&&1===h)&&this.focusItem(l),this.active_=!0}else this.hideResults(),this.active_=!1},a.Autocompleter.prototype.showResult=function(b,c){return a.isFunction(this.options.showResult)?this.options.showResult(b,c):a("

    ").text(b).html()},a.Autocompleter.prototype.autoFill=function(a,b){var c,d,e,f;if(this.options.autoFill&&8!==this.lastKeyPressed_&&(c=String(a).toLowerCase(),d=String(b).toLowerCase(),e=a.length,f=b.length,c.substr(0,f)===d)){var g=this.getDelimiterOffsets(),h=g.start?" ":"";this.setValue(h+a);var i=f+g.start+h.length,j=e+g.start+h.length;return this.selectRange(i,j),!0}return!1},a.Autocompleter.prototype.focusNext=function(){this.focusMove(1)},a.Autocompleter.prototype.focusPrev=function(){this.focusMove(-1)},a.Autocompleter.prototype.focusMove=function(b){var d=this.getItems();if(b=c(b,0))for(var e=0;eb?b=0:b>=d.length&&(b=d.length-1),c=a(d[b])):c=a(b),c&&c.addClass(this.selectClass_).addClass(this.options.selectClass))},a.Autocompleter.prototype.selectCurrent=function(){var b=a("li."+this.selectClass_,this.dom.$results);1===b.length?this.selectItem(b):this.deactivate(!1)},a.Autocompleter.prototype.selectItem=function(a){var b=a.data("value"),c=a.data("data"),d=this.displayValue(b,c),e=this.beforeUseConverter(d);this.lastProcessedValue_=e,this.lastSelectedValue_=e;var f=this.getDelimiterOffsets(),g=this.options.delimiterChar,h=this.dom.$elem,i=0;this.options.useDelimiter&&(h.val().substring(f.start-1,f.start)==g&&" "!=g&&(d=" "+d),h.val().substring(f.end,f.end+1)!=g&&this.lastKeyPressed_!=this.options.delimiterKeyCode?d+=g:i=1),this.setValue(d),this.setCaret(f.start+d.length+i),this.callHook("onItemSelect",{value:b,data:c}),this.deactivate(!0),h.focus()},a.Autocompleter.prototype.displayValue=function(b,c){return a.isFunction(this.options.displayValue)?this.options.displayValue(b,c):b},a.Autocompleter.prototype.hideResults=function(){this.dom.$results.hide()},a.Autocompleter.prototype.deactivate=function(a){this.finishTimeout_&&clearTimeout(this.finishTimeout_),this.keyTimeout_&&clearTimeout(this.keyTimeout_),a&&(this.lastProcessedValue_!==this.lastSelectedValue_&&(this.options.mustMatch&&this.setValue(""),this.callHook("onNoMatch")),this.active_&&this.callHook("onFinish"),this.lastKeyPressed_=null,this.lastProcessedValue_=null,this.lastSelectedValue_=null,this.active_=!1),this.hideResults()},a.Autocompleter.prototype.selectRange=function(a,b){var c=this.dom.$elem.get(0);if(c.setSelectionRange)c.focus(),c.setSelectionRange(a,b);else if(c.createTextRange){var d=c.createTextRange();d.collapse(!0),d.moveEnd("character",b),d.moveStart("character",a),d.select()}},a.Autocompleter.prototype.setCaret=function(a){this.selectRange(a,a)},a.Autocompleter.prototype.getCaret=function(){var a,b,c,d,e,f,g=this.dom.$elem,h=g[0];return h.createTextRange?(b=document.selection,"textarea"!=h.tagName.toLowerCase()?(a=g.val(),c=b.createRange().duplicate(),c.moveEnd("character",a.length),d=""===c.text?a.length:a.lastIndexOf(c.text),c=b.createRange().duplicate(),c.moveStart("character",-a.length),e=c.text.length):(c=b.createRange(),f=c.duplicate(),f.moveToElementText(h),f.setEndPoint("EndToEnd",c),d=f.text.length-c.text.length,e=d+c.text.length)):(d=g[0].selectionStart,e=g[0].selectionEnd),{start:d,end:e}},a.Autocompleter.prototype.setValue=function(a){if(this.options.useDelimiter){var b=this.dom.$elem.val(),c=this.getDelimiterOffsets(),d=b.substring(0,c.start),e=b.substring(c.end);a=d+a+e}this.dom.$elem.val(a)},a.Autocompleter.prototype.getValue=function(a){if(this.options.useDelimiter){var b=this.getDelimiterOffsets();return a.substring(b.start,b.end).trim()}return a},a.Autocompleter.prototype.getDelimiterOffsets=function(){var a=this.dom.$elem.val();if(this.options.useDelimiter){var b=a.substring(0,this.getCaret().start),c=b.lastIndexOf(this.options.delimiterChar)+1,d=a.substring(this.getCaret().start),e=d.indexOf(this.options.delimiterChar);-1==e&&(e=a.length),e+=this.getCaret().start}else c=0,e=a.length;return{start:c,end:e}}}(jQuery); //# sourceMappingURL=../../../maps/libs/jquery/jquery.autocomplete.js.map