/*
Copyright 2013, KISSY UI Library v1.31
MIT Licensed
build time: Jun 7 13:04
*/
KISSY.add("combobox/base",function(h,c,k,l,i,f){function a(e){for(var b=0;b<e.length;b++)if(!e[b].get("disabled"))return e[b];return null}function b(){this.get("input")[0].focus();s.call(this)}function d(e,b){var a=e.get("el"),d=e.get("prefixCls")+"combobox-invalid",o=e.get("invalidEl");b?(a.addClass(d),o.attr("title",b),o.show()):(a.removeClass(d),o.hide())}function o(e,b){var a=e.get("menu");if(a&&!a.isController)if(b)a=k.create(a,e),e.setInternal("menu",a);else return null;return a}function g(){var e=
o(this);e&&e.get("visible")&&this.alignInternal()}function j(){var e=this;e._focusoutDismissTimer=setTimeout(function(){e._focusoutDismissTimer&&e.set("collapsed",!0)},50)}function s(){var e;if(e=this._focusoutDismissTimer)clearTimeout(e),this._focusoutDismissTimer=null}function t(){var e;this._stopNotify||(e=this.getValueInternal(),e===f?this.set("collapsed",!0):(this._savedInputValue=e,this.sendRequest(e)))}function q(e){var b,a=[],d,f,c=o(this,1),e=this.normalizeData(e);c.removeChildren(!0);c.set("highlightedItem",
null);if(e&&e.length){for(f=0;f<e.length;f++)b=e[f],a.push(c.addChild(b));if(this.get("highlightMatchItem")){e=this.getValueInternal();for(f=0;f<a.length;f++)if(a[f].get("textContent")==e){c.set("highlightedItem",a[f]);d=!0;break}}if(!d&&this.get("autoHighlightFirst"))for(f=0;f<a.length;f++)if(!a[f].get("disabled")){c.set("highlightedItem",a[f]);break}this.set("collapsed",!1);g.call(this)}else this.set("collapsed",!0)}var r,i=c.all,m=c.KeyCodes,n={points:["bl","tl"],overflow:{adjustX:1,adjustY:1}},
p=i(h.Env.host);return r=k.Controller.extend({_savedInputValue:null,_stopNotify:0,normalizeData:function(e){var b,a,d;if(e&&e.length){e=e.slice(0,this.get("maxItemCount"));b=this.get("format")?this.get("format").call(this,this.getValueInternal(),e):[];for(d=0;d<e.length;d++)a=e[d],b[d]=h.mix({content:a,textContent:a,value:a},b[d])}return b},bindUI:function(){this.get("input").on("valuechange",t,this)},getValueInternal:function(){return this.get("input").val()},setValueInternal:function(e){this.get("input").val(e)},
alignInternal:function(){var e=this.get("menu"),b=h.clone(e.get("align"));b.node=this.get("el");h.mix(b,n,!1);e.set("align",b)},handleFocus:function(){var e;d(this,!1);(e=this.get("placeholderEl"))&&e.hide()},handleBlur:function(){var e=this,b=e.get("placeholderEl"),a;r.superclass.handleBlur.apply(e,arguments);j.call(e);a=e.get("input");e.validate(function(b,f){b?!e.get("focused")&&f==a.val()&&d(e,b):d(e,!1)});b&&!a.val()&&b.show()},handleMouseDown:function(b){var a,d;r.superclass.handleMouseDown.apply(this,
arguments);a=b.target;d=this.get("trigger");if(this.get("hasTrigger")&&(d[0]==a||d.contains(a)))a=this.get("input"),this.get("collapsed")?(a[0].focus(),this.sendRequest("")):this.set("collapsed",!0),b.preventDefault()},handleKeyEventInternal:function(b){var d,c=b.keyCode,g,j=o(this);this.get("input");if(d=this.get("updateInputOnDownUp"))this._stopNotify=h.inArray(b.keyCode,[m.UP,m.DOWN,m.ESC])?1:0;if(j&&j.get("visible")){g=j.get("activeItem");if(d&&g){var i=j.get("children");if(c==m.DOWN&&g==a(i.concat().reverse())||
c==m.UP&&g==a(i))return this.setValueInternal(this._savedInputValue),j.set("highlightedItem",null),!0}c=j.handleKeydown(b);if(b.keyCode==m.ESC)return this.set("collapsed",!0),d&&this.setValueInternal(this._savedInputValue),!0;g=j.get("activeItem");d&&h.inArray(b.keyCode,[m.DOWN,m.UP])&&this.setValueInternal(g.get("textContent"));return b.keyCode==m.TAB&&g&&(g.performActionInternal(),this.get("multiple"))?!0:c}(b.keyCode==m.DOWN||b.keyCode==m.UP)&&this.sendRequest(this.getValueInternal());return f},
syncUI:function(){var b=this.get("input"),a=this.get("inputValue");a!=f&&b.val(a);this.get("placeholder")&&(b.val()||this.get("placeholderEl").show())},validate:function(b){var a=this.get("validator"),d=this.get("input").val();a?a(d,function(a){b(a,d)}):b(!1,d)},bindMenu:function(){var a=this,d,f;f=a.get("menu");f.on("click",function(b){b=b.target.get("textContent");a._stopNotify=1;a.setValueInternal(b);a._savedInputValue=b;a.set("collapsed",!0);setTimeout(function(){a._stopNotify=0},50)});p.on("resize",
a.__repositionBuffer=h.buffer(g,50),a);d=f.get("el");f=f.get("contentEl");d.on("focusout",j,a);d.on("focusin",function(){setTimeout(function(){s.call(a)},0)},a);f.on("mouseover",b,a);f.on("mousedown",function(){a._stopNotify=1});f.on("mouseup",function(){a._stopNotify=0});a.bindMenu=h.noop},sendRequest:function(b){this.get("dataSource").fetchData(b,q,this)},_onSetCollapsed:function(b){if(b)(b=o(this))&&b.hide();else{var b=this.get("el"),a=o(this,1);s.call(this);if(a&&!a.get("visible")){a.render();
this.bindMenu();if(this.get("matchElWidth")){a.render();var d=a.get("el"),d=(parseInt(d.css("borderLeftWidth"))||0)+(parseInt(d.css("borderRightWidth"))||0);a.set("width",b[0].offsetWidth-d)}a.show();this.get("input").attr("aria-owns",a.get("el").attr("id"))}}},destructor:function(){var b=this.__repositionBuffer;b&&(p.detach("resize",b,this),b.stop())}},{ATTRS:{input:{view:1},inputValue:{view:1},trigger:{view:1},placeholder:{view:1},placeholderEl:{view:1},validator:{},invalidEl:{view:1},allowTextSelection:{value:!0},
hasTrigger:{view:1},menu:{value:{},setter:function(b){b&&b.isController&&b.setInternal("parent",this)}},defaultChildXClass:{value:"popupmenu"},collapsed:{view:1},dataSource:{},maxItemCount:{value:99999},matchElWidth:{value:!0},format:{},updateInputOnDownUp:{value:!0},autoHighlightFirst:{},highlightMatchItem:{value:!0},xrender:{value:l}}},{xclass:"combobox",priority:10})},{requires:["node","component/base","./render","menu"]});
KISSY.add("combobox",function(h,c,k,l,i,f){c.LocalDataSource=i;c.RemoteDataSource=f;c.FilterSelect=l;c.MultiValueComboBox=k;return c},{requires:["combobox/base","combobox/multi-value-combobox","combobox/filter-select","combobox/LocalDataSource","combobox/RemoteDataSource"]});
KISSY.add("combobox/cursor",function(h,c){function k(a){var b=i,d;b||(b=c.create(l));"textarea"==""+a.type?c.css(b,"width",c.css(a,"width")):c.css(b,"width",9999);h.each(f,function(d){c.css(b,d,c.css(a,d))});i||(d=a.ownerDocument.body,d.insertBefore(b,d.firstChild));return i=b}var l="<div style='z-index:-9999;overflow:hidden;position: fixed;left:-9999px;top:-9999px;opacity:0;white-space:pre-wrap;word-wrap:break-word;'></div>",i,f="paddingLeft,paddingTop,paddingBottom,paddingRight,marginLeft,marginTop,marginBottom,marginRight,borderLeftStyle,borderTopStyle,borderBottomStyle,borderRightStyle,borderLeftWidth,borderTopWidth,borderBottomWidth,borderRightWidth,line-height,outline,height,fontFamily,fontSize,fontWeight,fontVariant,fontStyle".split(",");
return function(a){var a=c.get(a),b=a.ownerDocument,d,f,g=a.scrollTop,j=a.scrollLeft;if(b.selection)return b=b.selection.createRange(),{left:b.boundingLeft+j+c.scrollLeft(),top:b.boundingTop+g+b.boundingHeight+c.scrollTop()};d=c.offset(a);if("textarea"!=a.type)return d.top+=a.offsetHeight,d;f=k(a);b=a.selectionStart;f.innerHTML=h.escapeHTML(a.value.substring(0,b-1))+"<span>x</span>";c.offset(f,d);d=f.lastChild;a=c.offset(d);a.top+=c.height(d);0<b&&(a.left+=c.width(d));a.top-=g;a.left-=j;return a}},
{requires:["dom"]});KISSY.add("combobox/filter-select",function(h,c){var k=c.extend({validate:function(c){var i=this;k.superclass.validate.call(i,function(f,a){f?c(f,a):i.get("dataSource").fetchData(a,function(b){a:{if(b=i.normalizeData(b))for(var d=0;d<b.length;d++)if(b[d].textContent==a){b=b[d];break a}b=!1}c(b?"":i.get("invalidMessage"),a,b)})})}},{ATTRS:{invalidMessage:{value:"invalid input"}}});return k},{requires:["./base"]});
KISSY.add("combobox/LocalDataSource",function(h){function c(){c.superclass.constructor.apply(this,arguments)}c.ATTRS={data:{value:[]},parse:{value:function(c,l){var i=[],f=0;if(!c)return l;h.each(l,function(a){-1!=a.indexOf(c)&&i.push(a);f++});return i}}};h.extend(c,h.Base,{fetchData:function(c,h,i){var f=this.get("parse"),a=this.get("data"),a=f(c,a);h.call(i,a)}});return c},{requires:["component/base"]});
KISSY.add("combobox/multi-value-combobox",function(h,c,k){function l(b,a){return a&&-1!=b.indexOf(a)}function i(b){var d=b.get("input"),c=d.val(),g=[],j=[],i=b.get("literal"),h=b.get("separator"),b=b.get("separatorType"),k=!1,r=b!=f,d=d.prop("selectionStart"),m,n,p=-1;for(m=0;m<c.length;m++)(n=c.charAt(m),i&&n==i&&(k=!k),k)?j.push(n):(m==d&&(p=g.length),r&&a.test(n))?(j.length&&g.push(j.join("")),j=[],j.push(n)):l(h,n)?b==f?(j.push(n),j.length&&g.push(j.join("")),j=[]):(j.length&&g.push(j.join("")),
j=[],j.push(n)):j.push(n);j.length&&g.push(j.join(""));g.length||g.push("");-1==p&&(b==f&&l(h,n)&&g.push(""),p=g.length-1);return{tokens:g,cursorPosition:d,tokenIndex:p}}var f="suffix",a=/\s|\xa0/;return k.extend({getValueInternal:function(){this.get("input");var b=i(this),a=b.tokens,c=b.tokenIndex,b=this.get("separator"),g=this.get("separatorType"),a=a[c],c=a.length-1;if(g!=f)if(l(b,a.charAt(0)))a=a.slice(1);else return;else g==f&&l(b,a.charAt(c))&&(a=a.slice(0,c));return a},setValueInternal:function(b){var d=
this.get("input"),c=i(this),g=c.tokens,c=Math.max(0,c.tokenIndex),j=this.get("separator"),h=this.get("separatorType"),k=g[c+1]||"",q=g[c];if(h!=f){if(g[c]=q.charAt(0)+b,!k||!a.test(k.charAt(0)))g[c]+=" "}else g[c]=b,b=q.length-1,l(j,q.charAt(b))?g[c]+=q.charAt(b):1==j.length&&(g[c]+=j);b=g.slice(0,c+1).join("").length;d.val(g.join(""));d.prop("selectionStart",b);d.prop("selectionEnd",b)},alignInternal:function(){if(this.get("alignWithCursor")){var b=i(this),a=b.tokens,f=this.get("menu"),g=b.cursorPosition,
j=b.tokenIndex,b=this.get("input"),a=a.slice(0,j).join("").length;0<a&&++a;b.prop("selectionStart",a);b.prop("selectionEnd",a);a=c(b);b.prop("selectionStart",g);b.prop("selectionEnd",g);f.set("xy",[a.left,a.top])}else k.prototype.alignInternal.apply(this,arguments)}},{ATTRS:{separator:{value:",;"},separatorType:{value:f},literal:{value:'"'},alignWithCursor:{}}},{xclass:"multi-value-combobox",priority:20})},{requires:["./cursor","./base"]});
KISSY.add("combobox/RemoteDataSource",function(h,c){function k(){k.superclass.constructor.apply(this,arguments);this.io=null;this.caches={}}k.ATTRS={paramName:{value:"q"},allowEmpty:{},cache:{},parse:{},xhrCfg:{value:{}}};h.extend(k,h.Base,{fetchData:function(h,i,f){var a=this,b,d=a.get("paramName"),k=a.get("parse"),g=a.get("cache"),j=a.get("allowEmpty");a.io&&(a.io.abort(),a.io=null);if(!h&&!0!==j)return i.call(f,[]);if(g&&(b=a.caches[h]))return i.call(f,b);b=a.get("xhrCfg");b.data=b.data||{};b.data[d]=
h;b.success=function(b){k&&(b=k(h,b));a.setInternal("data",b);g&&(a.caches[h]=b);i.call(f,b)};a.io=c(b)}});return k},{requires:["ajax"]});
KISSY.add("combobox/render",function(h,c,k){var l=h.all,i=c.Render.extend({createDom:function(){var c,a=this.get("input"),b=this.get("prefixCls"),d=this.get("el"),i=this.get("trigger");this.get("srcNode")||(d.append(h.substitute('<div class="{prefixCls}combobox-input-wrap"></div>',{prefixCls:b})),c=d.one("."+b+"combobox-input-wrap"),a=a||h.all(h.substitute('<input aria-haspopup="true" aria-autocomplete="list" aria-haspopup="true" role="autocomplete" autocomplete="off" class="{prefixCls}combobox-input" />',{prefixCls:b})),
c.append(a),this.setInternal("input",a));i||this.setInternal("trigger",h.all(h.substitute('<div class="{prefixCls}combobox-trigger"><div class="{prefixCls}combobox-trigger-inner">&#x25BC;</div></div>',{prefixCls:b})));this.get("trigger").unselectable(k);this.setInternal("invalidEl",l("<div class='"+b+"combobox-invalid-el'><div class='"+b+"combobox-invalid-inner'></div></div>").insertBefore(a.parent(k,k),k));if(i=this.get("placeholder")){if(!(c=a.attr("id")))a.attr("id",c=h.guid("ks-combobox-input"));
this.setInternal("placeholderEl",l('<label for="'+c+'" class="'+b+'combobox-placeholder">'+i+"</label>").appendTo(d))}},getKeyEventTarget:function(){return this.get("input")},_onSetCollapsed:function(c){this.get("input").attr("aria-expanded",c)},_onSetHasTrigger:function(c){var a=this.get("trigger");c?this.get("el").prepend(a):a.remove()},_onSetDisabled:function(c){i.superclass._onSetDisabled.apply(this,arguments);this.get("input").attr("disabled",c)}},{ATTRS:{collapsed:{value:!0},hasTrigger:{value:!0},
input:{},trigger:{},placeholder:{},placeholderEl:{},invalidEl:{}},HTML_PARSER:{input:function(c){return c.one("."+this.get("prefixCls")+"combobox-input")},trigger:function(c){return c.one("."+this.get("prefixCls")+"combobox-trigger")}}});return i},{requires:["component/base"]});
