autocomplete-base-min.js revision c1fa7383daa25ffc775ef46e12aedd49d03d3ed7
YUI.add("autocomplete-base",function(G){var I=G.Lang,M=G.Array,D=I.isFunction,Q=I.isNumber,C="allowBrowserAutocomplete",N="dataSource",H="inputNode",V="minQueryLength",U="query",R="queryDelay",B="requestTemplate",J="resultFilters",F="resultFormatter",E="resultHighlighter",W="resultLocator",K="results",P="valueChange",A="clear",S=U,L=K,O=P;function T(){this.publish(A,{defaultFn:this._defClearFn,queueable:true});this.publish(S,{defaultFn:this._defQueryFn,queueable:true});this.publish(L,{defaultFn:this._defResultsFn,queueable:true});this.publish(O,{preventable:false,queueable:true});}T.ATTRS={allowBrowserAutocomplete:{value:false,writeOnce:"initOnly"},dataSource:{validator:function(X){return(X&&D(X.sendRequest))||X===null;}},inputNode:{setter:G.one,writeOnce:"initOnly"},minQueryLength:{validator:Q,value:1},query:{readOnly:true,value:null},queryDelay:{validator:function(X){return Q(X)&&X>=0;},value:150},requestTemplate:{setter:function(X){if(D(X)){return X;}X=X.toString();return function(Y){return X.replace(/(^|[^\\])((\\{2})*)\{query\}/,"$1$2"+encodeURIComponent(Y)).replace(/(^|[^\\])((\\{2})*)\\(\{query\})/,"$1$2$4");};},value:encodeURIComponent},resultFilters:{validator:I.isArray,value:[]},resultFormatter:{validator:"_functionValidator"},resultHighlighter:{validator:"_functionValidator"},resultLocator:{setter:function(X){if(X===null||D(X)){return X;}X=X.toString().split(".");return function(Y){return G.Object.getValue(Y,X);};}},results:{readOnly:true,value:[]}};T.CSS_PREFIX="ac";T.prototype={bindInput:function(){var X=this.get(H);if(!X){G.error("No inputNode specified.");}this.unbindInput();this._inputEvents=[X.on(P,this._onValueChange,this)];},syncInput:function(){var X=this.get(H);if(X.get("nodeName").toLowerCase()==="input"){X.setAttribute("autocomplete",this.get(C)?"on":"off");}},unbindInput:function(){while(this._inputEvents&&this._inputEvents.length){this._inputEvents.pop().detach();}},_functionValidator:function(X){return D(X)||X===null;},_parseResponse:function(h,Y,c){var m={data:c,query:h,results:[]},d,l,n,Z=Y&&Y.results,b=[],X,k,j,a,g,e,f;if(Z){X=this.get(J);k=this.get(F);j=this.get(E);e=this.get(W);if(e){l=M.map(Z,e);f=M.hash(l,Z);}else{l=Z;}for(a=0,g=X.length;a<g;++a){l=X[a](h,l);if(!l||!l.length){break;}}if(e){n=l;l=[];for(a=0,g=n.length;a<g;++a){l.push(f[n[a]]);}}else{n=[].concat(l);}d=j?j(h,n):[].concat(n);if(k){d=k(h,l,d,n);}for(a=0,g=d.length;a<g;++a){b.push({display:d[a],raw:l[a],text:n[a]});}m.results=b;}this.fire(L,m);},_parseValue:function(X){return X;},_onResponse:function(Y){var X=Y&&Y.callback&&Y.callback.query;if(X&&X===this.get(U)){this._parseResponse(X,Y.response,Y.data);}},_onValueChange:function(c){var X,Y,b=c.newVal,a=this._parseValue(b),Z;this.fire(O,{newVal:b,prevVal:c.prevVal});if(a.length>=this.get(V)){X=this.get(R);Z=this;Y=function(){Z.fire(S,{inputValue:b,query:a});};if(X){clearTimeout(this._delay);this._delay=setTimeout(Y,X);}else{Y();}}else{clearTimeout(this._delay);this.fire(S,{inputValue:b,query:null});}if(!b.length){this.fire(A,{prevVal:c.prevVal});}},_defClearFn:function(){this._set(K,[]);},_defQueryFn:function(Y){var Z=this.get(N),X=Y.query;this._set(U,X);if(X&&Z){Z.sendRequest({request:this.get(B)(X),callback:{query:X,success:G.bind(this._onResponse,this)}});}},_defResultsFn:function(X){this._set(K,X[K]);}};G.AutoCompleteBase=T;},"@VERSION@",{requires:["array-extras","event-valuechange","node-base"]});