autocomplete-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"]});YUI.add("autocomplete-list",function(B){var U=B.Node,J=B.Array,H=40,I=13,K=27,O=9,N=38,R="_CLASS_ITEM",S="_CLASS_ITEM_ACTIVE",C="_CLASS_ITEM_HOVER",T="_SELECTOR_ITEM",F="activeItem",M="circular",Q="hoveredItem",D="inputNode",E="item",P="visible",G="width",L="select",A=B.Base.create("autocompleteList",B.Widget,[B.AutoCompleteBase,B.WidgetPosition,B.WidgetPositionAlign,B.WidgetStack],{CONTENT_TEMPLATE:"<ul/>",ITEM_TEMPLATE:"<li/>",initializer:function(){this.publish(L,{defaultFn:this._defSelectFn});this._events=[];this._inputNode=this.get(D);this[R]=this.getClassName(E);this[S]=this.getClassName(E,"active");this[C]=this.getClassName(E,"hover");this[T]="."+this[R];if(!this._inputNode){B.error("No inputNode specified.");}if(!this.get("align.node")){this.set("align.node",this._inputNode);}if(!this.get(G)){this.set(G,this._inputNode.get("offsetWidth"));}},destructor:function(){this.unbindInput();while(this._events.length){this._events.pop().detach();}},bindUI:function(){this._bindInput();this._bindList();},renderUI:function(){this._contentBox=this.get("contentBox").set("role","listbox");this._inputNode.addClass(this.getClassName("input")).setAttrs({"aria-autocomplete":"list","aria-owns":this._contentBox.get("id"),role:"combobox"});},syncUI:function(){this.syncInput();this._syncResults();this._syncVisibility();},hide:function(){return this.set(P,false);},selectItem:function(V){if(V){if(!V.hasClass(this[R])){return;}}else{V=this.get(F);if(!V){return;}}this.fire(L,{result:V.getData("result")});return this;},show:function(){return this.set(P,true);},_activateNextItem:function(){var X=this.get(F),W=this[T],V;if(X){V=X.next(W)||(this.get(M)&&X.get("parentNode").one(W));if(V){this._set(F,V);}}return this;},_activatePrevItem:function(){var X=this.get(F),V=this[T],W;if(X){W=X.previous(V)||(this.get(M)&&X.get("parentNode").one(V+":last-child"));if(W){this._set(F,W);}}return this;},_add:function(V){var W=[];J.each(B.Lang.isArray(V)?V:[V],function(X){W.push(this._createItemNode(X.display).setData("result",X));},this);W=B.all(W);this._contentBox.append(W.toFrag());return W;},_bindInput:function(){var V=this._inputNode;this.bindInput();this._events.concat([V.on("blur",this._onInputBlur,this),V.on(B.UA.gecko?"keypress":"keydown",this._onInputKey,this)]);},_bindList:function(){this._events.concat([this.after("mouseover",this._afterMouseOver,this),this.after("mouseout",this._afterMouseOut,this),this.after("activeItemChange",this._afterActiveItemChange,this),this.after("hoveredItemChange",this._afterHoveredItemChange,this),this.after("resultsChange",this._afterResultsChange,this),this.after("visibleChange",this._afterVisibleChange,this),this._contentBox.delegate("click",this._onItemClick,this[T],this)]);
},_clear:function(){this._set(F,null);this._set(Q,null);this._contentBox.get("children").remove(true);},_createItemNode:function(V){var W=U.create(this.ITEM_TEMPLATE);return W.append(V).setAttrs({id:B.stamp(W),role:"option"}).addClass(this[R]);},_syncResults:function(W){var V;if(!W){W=this.get("results");}this._clear();if(W.length){V=this._add(W);this._set(F,V.item(0));}},_syncVisibility:function(V){if(V===undefined){V=this.get(P);}this._contentBox.set("aria-hidden",!V);if(!V){this._set(F,null);this._set(Q,null);}},_afterActiveItemChange:function(V){if(V.prevVal){V.prevVal.removeClass(this[S]);}if(V.newVal){V.newVal.addClass(this[S]);}},_afterHoveredItemChange:function(V){if(V.prevVal){V.prevVal.removeClass(this[C]);}if(V.newVal){V.newVal.addClass(this[C]);}},_afterMouseOver:function(V){var W=V.domEvent.target.ancestor("."+this[R],true);this._mouseOverList=true;if(W){this._set(Q,W);}},_afterMouseOut:function(){this._mouseOverList=false;this._set(Q,null);},_afterResultsChange:function(V){this._syncResults(V.newVal);this.set(P,!!V.newVal.length);},_afterVisibleChange:function(V){this._syncVisibility(!!V.newVal);},_onInputBlur:function(V){if(this._mouseOverList&&this._lastInputKey!==O){this._inputNode.focus();}else{this.hide();}},_onInputKey:function(W){var V=W.keyCode;this._lastInputKey=V;if(this.get(P)){switch(V){case H:this._activateNextItem();break;case I:this.selectItem();break;case K:this.hide();break;case N:this._activatePrevItem();break;default:return;}W.preventDefault();}},_onItemClick:function(V){V.preventDefault();this.selectItem(V.currentTarget);},_defSelectFn:function(V){this.hide();this._inputNode.set("value",V.result.text).focus();}},{ATTRS:{activeItem:{readOnly:true,value:null},align:{value:{points:["tl","bl"]}},circular:{value:true},hoveredItem:{readOnly:true,value:null},visible:{value:false}},CSS_PREFIX:B.ClassNameManager.getClassName("aclist")});B.AutoCompleteList=A;B.AutoComplete=A;},"@VERSION@",{requires:["autocomplete-base","widget","widget-position","widget-position-align","widget-stack"],skinnable:true});YUI.add("autocomplete",function(A){},"@VERSION@",{use:["autocomplete-base","autocomplete-list"]});