/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:21
*/
KISSY.add("combobox/base",function(f,h,a,g,j,C,m){function d(b,e){var c=b.get("menu");if(c&&c.xclass)if(e)c=a.create(c,b),b.__set("menu",c);else return null;return c}function k(){var b=d(this);if(b&&b.get("visible"))if(this.get("multiple")&&this.get("alignWithCursor")){var e=t(this),c=e.tokens,b=this.get("menu"),i=e.cursorPosition,a=e.tokenIndex,e=this.get("input"),c=c.slice(0,a).join("").length;0<c&&++c;e.prop("selectionStart",c);e.prop("selectionEnd",c);c=e.prop("KsCursorOffset");e.prop("selectionStart",
i);e.prop("selectionEnd",i);b.set("xy",[c.left,c.top])}else b=this.get("menu"),i=f.clone(b.get("align")),i.node=this.get("el"),f.mix(i,z,!1),b.set("align",i)}function s(){var b=this;b._focusoutDismissTimer=setTimeout(function(){b.set("collapsed",!0)},30)}function o(){var b;if(b=this._focusoutDismissTimer)clearTimeout(b),this._focusoutDismissTimer=null}function p(b,e){var c=b.get("input");if(b.get("multiple")){var i=t(b),a=i.tokens,i=Math.max(0,i.tokenIndex),d=b.get("separator"),g=b.get("separatorType"),
f=a[i];a[i]=f&&-1!=d.indexOf(f.charAt(0))?f.charAt(0):"";a[i]+=e;f=a[i+1];if(g==r&&(!f||-1==d.indexOf(f.charAt(0))))a[i]+=d.charAt(0);i=a.slice(0,i+1).join("").length;c.val(a.join(""));c.prop("selectionStart",i);c.prop("selectionEnd",i)}else c.val(e)}function q(b){var e=b.get("input").val();if(b.get("multiple")){var c=t(b),e=c.tokens,c=c.tokenIndex,a=b.get("separator"),b=b.get("separatorType");return(e=e[c]||"")&&-1!=a.indexOf(e.charAt(0))?e.substring(1):b==r&&(0==c||-1==c)?e:m}return e}function A(){if(!this._stopNotify){var b=
q(this);b===m?this.set("collapsed",!0):(this._savedInputValue=b,this.sendRequest(b))}}function B(b){var e,c=[],a,g,l,j=d(this,1);j.removeChildren(!0);if(b&&b.length){b=b.slice(0,this.get("maxItemCount"));a=this.get("format")?this.get("format").call(this,q(this),b):[];for(l=0;l<b.length;l++)e=b[l],c.push(j.addChild(f.mix({xclass:"menuitem",content:e,textContent:e,value:e},a[l])));b=q(this);for(l=0;l<c.length;l++)if(c[l].get("textContent")==b){j.set("highlightedItem",c[l]);g=!0;break}if(!g&&this.get("autoHighlightFirst"))for(l=
0;l<c.length;l++)if(!c[l].get("disabled")){j.set("highlightedItem",c[l]);break}this.set("collapsed",!1)}else this.set("collapsed",!0)}function u(){var b=this.get("input");this.get("collapsed")?(b[0].focus(),this.sendRequest("")):this.set("collapsed",!0)}function v(b){b.preventDefault()}function t(b){for(var e=b.get("input"),c=e.val(),a=[],d=[],f=b.get("literal"),g=b.get("separator"),j=!1,b=b.get("whitespace"),e=e.prop("selectionStart"),h=-1,k=0;k<c.length;k++){var m=c.charAt(k);k==e&&(h=a.length);
if(!j&&(!b&&/\s|\xa0/.test(m)&&(a.push(d.join("")),d=[]),-1!=g.indexOf(m)))a.push(d.join("")),d=[];f&&m==f&&(j=!j);d.push(m)}d.length&&a.push(d.join(""));-1==h&&(h=a.length-1);return{tokens:a,cursorPosition:e,tokenIndex:h}}var w,j=h.all,n=h.KeyCodes,z={points:["bl","tl"],overflow:{adjustX:1,adjustY:1}},x=j(f.Env.host),r="suffix",y=f.buffer(k,50);return w=a.Controller.extend({_savedInputValue:null,_stopNotify:0,bindUI:function(){this.get("input").on("valuechange",A,this)},bindMenu:function(){var b=
this,e,a;a=b.get("menu");a.on("click",function(a){a=a.target;b._stopNotify=1;b._selectItem(a);b.set("collapsed",!0);setTimeout(function(){b._stopNotify=0},50)});x.on("resize",y,b);e=a.get("el");a=a.get("contentEl");e.on("focusout",s,b);e.on("focusin",o,b);a.on("mouseover",function(){b.get("input")[0].focus();o.call(b)});b.bindMenu=f.noop},_uiSetHasTrigger:function(b){var a=this.get("trigger");b?(a.on("click",u,this),a.on("mousedown",v)):(a.detach("click",u,this),a.detach("mousedown",v))},sendRequest:function(b){this.get("dataSource").fetchData(b,
B,this)},_uiSetCollapsed:function(b){if(b)(b=d(this))&&b.hide();else{var b=this.get("el"),a=d(this,1);o.call(this);a&&!a.get("visible")&&(a.render(),this.bindMenu(),this.get("matchElWidth")&&a.set("width",b.innerWidth()),a.show(),k.call(this),this.get("input").attr("aria-owns",a.get("el")[0].id))}},handleBlur:function(){w.superclass.handleBlur.apply(this,arguments);s.call(this)},handleKeyEventInternal:function(b){this.get("input");var a=d(this);if(a){var c=this.get("updateInputOnDownUp");c&&(this._stopNotify=
f.inArray(b.keyCode,[n.UP,n.DOWN,n.ESC])?1:0);var g;if(a.get("visible")){var j=a.handleKeydown(b);c&&f.inArray(b.keyCode,[n.DOWN,n.UP])&&p(this,a.get("activeItem").get("textContent"));if(b.keyCode==n.ESC)return this.set("collapsed",!0),c&&p(this,this._savedInputValue),!0;if(b.keyCode==n.TAB&&(g=a.get("activeItem")))if(g.performActionInternal(),this.get("multiple"))return!0;return j}if(b.keyCode==n.DOWN||b.keyCode==n.UP)return this.sendRequest(q(this)),!0}},_selectItem:function(b){if(b){var a=b.get("textContent"),
c=this.get("separatorType");p(this,a+(c==r?"":" "));this._savedInputValue=a;this.fire("click",{target:b})}},destructor:function(){x.detach("resize",y,this)}},{ATTRS:{input:{view:1},trigger:{view:1},allowTextSelection:{value:!0},hasTrigger:{view:1},menu:{value:{xclass:"popupmenu"},setter:function(b){b instanceof a.Controller&&b.__set("parent",this)}},collapsed:{view:1},dataSource:{setter:function(b){return a.create(b)}},maxItemCount:{value:99999},matchElWidth:{value:!0},format:{},multiple:{},separator:{value:",;"},
separatorType:{value:r},whitespace:{valueFn:function(){return this.get("separatorType")==r}},updateInputOnDownUp:{value:!0},literal:{value:'"'},alignWithCursor:{},autoHighlightFirst:{},xrender:{value:g}}},{xclass:"combobox",priority:10})},{requires:["node","component","./baseRender","input-selection","menu"]});
KISSY.add("combobox/baseRender",function(f,h){return h.Render.extend({createDom:function(){var a,g;a=this.get("el");var j=this.get("trigger");this.get("srcNode")||(a.append('<div class="ks-combobox-input-wrap"></div>'),a=a.one(".ks-combobox-input-wrap"),g=this.get("input")||f.all('<input aria-haspopup="true" aria-combobox="list" aria-haspopup="true" role="combobox" combobox="off" class="ks-combobox-input" />'),a.append(g),this.__set("input",g));j||this.__set("trigger",f.all('<div class="ks-combobox-trigger"><div class="ks-combobox-trigger-inner">&#x25BC;</div></div>'));
this.get("trigger").unselectable()},getKeyEventTarget:function(){return this.get("input")},_uiSetCollapsed:function(a){this.get("input").attr("aria-expanded",a)},_uiSetHasTrigger:function(a){var g=this.get("trigger");a?this.get("el").prepend(g):g.remove()}},{ATTRS:{collapsed:{},hasTrigger:{value:!0},input:{},trigger:{}},HTML_PARSER:{input:function(a){return a.one(".ks-combobox-input")},trigger:function(a){return a.one(".ks-combobox-trigger")}}})},{requires:["component"]});
KISSY.add("combobox",function(f,h,a,g){h.LocalDataSource=a;h.RemoteDataSource=g;return h},{requires:["combobox/base","combobox/LocalDataSource","combobox/RemoteDataSource"]});
KISSY.add("combobox/LocalDataSource",function(f,h){function a(){a.superclass.constructor.apply(this,arguments)}a.ATTRS={data:{value:[]},parse:{value:function(a,j){var h=[],m=0;if(!a)return j;f.each(j,function(d){-1!=d.indexOf(a)&&h.push(d);m++});return h}}};f.extend(a,f.Base,{fetchData:function(a,f,h){var m=this.get("parse"),d=this.get("data"),d=m(a,d);f.call(h,d)}});h.Manager.setConstructorByXClass("combobox-LocalDataSource",a);return a},{requires:["component"]});
KISSY.add("combobox/RemoteDataSource",function(f,h,a){function g(){g.superclass.constructor.apply(this,arguments);this.io=null;this.caches={}}g.ATTRS={paramName:{value:"q"},allowEmpty:{},cache:{},parse:{},xhrCfg:{value:{}}};f.extend(g,f.Base,{fetchData:function(a,f,g){var d=this,k,s=d.get("paramName"),o=d.get("parse"),p=d.get("cache"),q=d.get("allowEmpty");d.io&&(d.io.abort(),d.io=null);if(!a&&!0!==q)return f.call(g,[]);if(p&&(k=d.caches[a]))return f.call(g,k);k=d.get("xhrCfg");k.data=k.data||{};
k.data[s]=a;k.success=function(h){o&&(h=o(a,h));d.__set("data",h);p&&(d.caches[a]=h);f.call(g,h)};d.io=h(k)}});a.Manager.setConstructorByXClass("combobox-RemoteDataSource",g);return g},{requires:["ajax","component"]});
