|
|
(function(n,t){"use strict";function ut(t){var i,r,f;for(t=n.extend({},s,t||{}),u===null&&(u=n("body")),i=n(this),r=0,f=i.length;r<f;r++)ft(i.eq(r),t);return i}function ft(t,i){var u,f,e,r;if(!t.hasClass("autocompleter-node")){i=n.extend({},i,t.data("autocompleter-options"));u='<div class="autocompleter '+i.customClass.join(" ")+'" id="autocompleter-'+(v+1)+'">';i.hint&&(u+='<div class="autocompleter-hint"><\/div>');u+='<ul class="autocompleter-list"><\/ul>';u+="<\/div>";t.addClass("autocompleter-node").after(u);f=t.next(".autocompleter").eq(0);e=t.attr("autocomplete");t.attr("autocomplete","off");r=n.extend({$node:t,$autocompleter:f,$selected:null,$list:null,index:-1,hintText:!1,source:!1,jqxhr:!1,response:null,focused:!1,query:"",originalAutocomplete:e,guid:v++},i);r.$autocompleter.on("mousedown.autocompleter",".autocompleter-item",r,b).data("autocompleter",r);r.$node.on("keyup.autocompleter",r,st).on("keydown.autocompleter",r,ht).on("focus.autocompleter",r,ct).on("blur.autocompleter",r,lt).on("mousedown.autocompleter",r,at)}}function et(n,t,i){var u=[],f,r;if(n=n.toUpperCase(),t.length)for(f=0;f<2;f++)for(r in t)if("clear,insert,remove".indexOf(r)===-1&&u.length<i)switch(f){case 0:t[r].label.toUpperCase().search(n)===0&&(u.push(t[r]),delete t[r]);break;case 1:t[r].label.toUpperCase().search(n)!==-1&&(u.push(t[r]),delete t[r])}return u}function h(t){var i,r;if(t.query=n.trim(t.$node.val()),t.empty||t.query.length!==0)typeof t.source=="object"?(e(t),i=et(t.query,dt(t.source),t.limit),i.length&&c(i,t)):(t.jqxhr&&t.jqxhr.abort(),r=n.extend({limit:t.limit,query:t.query},t.combine()),t.jqxhr=n.ajax({url:t.source,dataType:"json",data:r,beforeSend:function(n){if(t.$autocompleter.addClass("autocompleter-ajax"),e(t),t.cache){var i=kt(this.url);i&&(n.abort(),c(i,t))}}}).done(function(n){t.offset&&(n=wt(n,t.offset));t.cache&&bt(this.url,n);c(n,t)}).always(function(){t.$autocompleter.removeClass("autocompleter-ajax")}));else{e(t);return}}function e(n){n.response=null;n.$list=null;n.$selected=null;n.index=0;n.$autocompleter.find(".autocompleter-list").empty();n.$autocompleter.find(".autocompleter-hint").removeClass("autocompleter-hint-show").empty();n.hintText=!1;i(null,n)}function c(n,t){ot(n,t);t.$autocompleter.hasClass("autocompleter-focus")&&l(null,t)}function ot(t,i){for(var f,s,e,o,v,h,y,c,l="",r=0,p=t.length;r<p;r++){f=["autocompleter-item"];i.selectFirst&&r===0&&!i.changeWhenSelect&&f.push("autocompleter-item-selected");var w=new RegExp(i.query,"gi"),u=i.customLabel&&t[r][i.customLabel]?t[r][i.customLabel]:t[r].label,a=u;if(u=i.highlightMatches?u.replace(w,"<strong>$&<\/strong>"):u,s=i.customValue&&t[r][i.customValue]?t[r][i.customValue]:t[r].value,i.template){e=i.template.replace(/({{ label }})/gi,u);for(o in t[r])t[r].hasOwnProperty(o)&&(v=new RegExp("{{ "+o+" }}","gi"),e=e.replace(v,t[r][o]));u=e}l+=s?'<li data-value="'+s+'" data-label="'+a+'" class="'+f.join(" ")+'">'+u+"<\/li>":'<li data-label="'+a+'" class="'+f.join(" ")+'">'+u+"<\/li>"}t.length&&i.hint&&(h=t[0].label.substr(0,i.query.length).toUpperCase()===i.query.toUpperCase()?t[0].label:!1,h&&i.query!==t[0].label&&(y=new RegExp(i.query,"i"),c=h.replace(y,"<span>"+i.query+"<\/span>"),i.$autocompleter.find(".autocompleter-hint").addClass("autocompleter-hint-show").html(c),i.hintText=c));i.response=t;i.$autocompleter.find(".autocompleter-list").html(l);i.$selected=i.$autocompleter.find(".autocompleter-item-selected").length?i.$autocompleter.find(".autocompleter-item-selected"):null;i.$list=t.length?i.$autocompleter.find(".autocompleter-item"):null;i.index=i.$selected?i.$list.index(i.$selected):-1;i.$autocompleter.find(".autocompleter-item").each(function(t,r){n(r).data(i.response[t])})}function st(t){var i=t.data,e=t.keyCode?t.keyCode:t.which,f,r,u;(e===40||e===38)&&i.$autocompleter.hasClass("autocompleter-show")?(f=i.$list.length,f&&(f>1?i.index===f-1?(r=i.changeWhenSelect?-1:0,u=i.index-1):i.index===0?(r=i.index+1,u=i.changeWhenSelect?-1:f-1):i.index===-1?(r=0,u=f-1):(r=i.index+1,u=i.index-1):i.index===-1?(r=0,u=0):(u=-1,r=-1),i.index=e===40?r:u,i.$list.removeClas
|