/*
Copyright 2012, KISSY UI Library v1.30rc
MIT Licensed
build time: Jul 11 21:24
*/
KISSY.add("menubutton/base",function(d,e,g,k,i,l,j){function f(c,m){var a=c.get("menu");if(a&&a.xclass)if(m)a=l.create(a,c),c.__set("menu",a);else return null;return a}function o(){var c=f(this);if(c&&c.get("visible")){var m=d.clone(c.get("align"));m.node=this.get("el");d.mix(m,a,!1);c.set("align",m)}}var p=d.Env.host,n=d.buffer(o,50),q=e.all,h=e.KeyCodes,a={points:["bl","tl"],overflow:{adjustX:1,adjustY:1}},b=g.extend([l.DecorateChild],{_uiSetCollapsed:function(c){if(c)(c=f(this))&&c.hide();else{var c=
this.get("el"),a=f(this,1);a&&!a.get("visible")&&(a.render(),this.bindMenu(),this.get("matchElWidth")&&a.set("width",c.innerWidth()),a.show(),o.call(this),c.attr("aria-haspopup",a.get("el").attr("id")))}},bindMenu:function(){var c=this,a=c.get("menu");a.on("afterActiveItemChange",function(a){c.set("activeItem",a.newVal)});q(p).on("resize",n,c);if(c.get("collapseOnClick"))a.on("click",function(){c.set("collapsed",!0)});c.bindMenu=d.noop},handleKeyEventInternal:function(a){var b=f(this);if(a.keyCode==
h.SPACE){if(a.preventDefault(),"keyup"!=a.type)return j}else if("keydown"!=a.type)return j;return b&&b.get("visible")?(b=b.handleKeydown(a),a.keyCode==h.ESC?(this.set("collapsed",!0),!0):b):a.keyCode==h.SPACE||a.keyCode==h.DOWN||a.keyCode==h.UP?(this.set("collapsed",!1),!0):j},performActionInternal:function(){this.set("collapsed",!this.get("collapsed"))},handleBlur:function(a){b.superclass.handleBlur.call(this,a);this.set("collapsed",!0)},addItem:function(a,b){f(this,1).addChild(a,b)},removeItem:function(a,
b){var d=f(this);d&&d.removeChild(a,b)},removeItems:function(a){var b=this.get("menu");b&&(b.removeChildren?b.removeChildren(a):b.children&&(b.children=[]))},getItemAt:function(a){var b=f(this);return b&&b.getChildAt(a)},_uiSetDisabled:function(a){!a&&this.set("collapsed",!0)},decorateChildrenInternal:function(a,b){d.one(b[0].ownerDocument.body).prepend(b);this.__set("menu",new a(d.mix({srcNode:b,prefixCls:this.get("prefixCls")})))},destructor:function(){q(p).detach("resize",n,this);var a=this.get("menu");
a.destroy&&a.destroy()}},{ATTRS:{activeItem:{view:1},matchElWidth:{value:!0},collapseOnClick:{value:!1},decorateChildCls:{valueFn:function(){return this.get("prefixCls")+"popupmenu"}},menu:{value:{xclass:"popupmenu"},setter:function(a){a instanceof i&&a.__set("parent",this)}},collapsed:{view:1},xrender:{value:k}}},{xclass:"menu-button",priority:20});return b},{requires:["node","button","./baseRender","menu","component"]});
KISSY.add("menubutton/baseRender",function(d,e){return e.Render.extend({createDom:function(){this.get("el").append('<div class="ks-inline-block ks-menu-button-dropdown"><div class="ks-menu-button-dropdown-inner"></div></div>').attr("aria-haspopup",!0)},_uiSetCollapsed:function(d){var e=this.get("el"),i=this.getCssClassWithPrefix("menu-button-open");e[d?"removeClass":"addClass"](i).attr("aria-expanded",!d)},_uiSetActiveItem:function(d){this.get("el").attr("aria-activedescendant",d&&d.get("el").attr("id")||
"")}},{ATTRS:{contentEl:{valueFn:function(){return d.all('<div class="ks-inline-block ks-menu-button-caption"></div>')}},contentElCls:{value:"ks-menu-button-caption"},activeItem:{},collapsed:{value:!0}}})},{requires:["button"]});KISSY.add("menubutton",function(d,e,g,k,i){e.Render=g;e.Select=k;e.Option=i;return e},{requires:["menubutton/base","menubutton/baseRender","menubutton/select","menubutton/option"]});
KISSY.add("menubutton/option",function(d,e){var g=e.Item.extend({handleBlur:function(){return g.superclass.handleBlur.apply(this,arguments)}},{ATTRS:{selectable:{value:!0},textContent:{}}},{xclass:"option",priority:10});return g},{requires:["menu"]});
KISSY.add("menubutton/select",function(d,e,g,k,i,l){function j(a){var b=a.get("menu"),b=b.children||b.get&&b.get("children")||[],a=a.get("value"),c,d;for(d=0;d<b.length;d++)if(c=b[d],f(c)==a)return c;return null}function f(a){var b;if(a)if(a.get){if((b=a.get("value"))===l)b=a.get("textContent")||a.get("content")}else if((b=a.value)===l)b=a.textContent||a.content;return b}function o(a){var b=a.get("menu"),c=a.get("value"),a=b&&b.get&&b.get("children");d.each(a,function(a){a&&a.set&&a.set("selected",
f(a)==c)})}function p(){var a=j(this),b=this.get("menu");b.set("highlightedItem",a||b.getChildAt(0));a&&a.set("selected",!0)}function n(a){var b=j(a),c=b&&(b.textContent||b.get&&b.get("textContent")),b=b&&(b.content||b.get&&b.get("content"));a.set("content",c||b||a.get("defaultCaption"))}function q(a){a=a.target;a instanceof k.Item&&this.set("value",f(a))}var h=g.extend({bindUI:function(){this.on("click",q,this)},bindMenu:function(){h.superclass.bindMenu.call(this);this.get("menu").on("show",p,this)},
removeItems:function(){h.superclass.removeItems.apply(this,arguments);this.set("value",null)},removeItem:function(a){h.superclass.removeItem.apply(this,arguments);a.get("value")==this.get("value")&&this.set("value",null)},_uiSetValue:function(){o(this);n(this)},_uiSetDefaultCaption:function(){n(this)}},{ATTRS:{value:{},defaultCaption:{value:""},collapseOnClick:{value:!0}},decorate:function(a,b){a=d.one(a);b=b||{};b.elBefore=a;var c,f=[],g,i=null,j=a.val();a.all("option").each(function(a){var b={content:a.text(),
elCls:a.attr("class"),value:a.val(),xclass:"option"};j==a.val()&&(i={content:b.content,value:b.value});f.push(b)});d.mix(b,{menu:d.mix({xclass:"popupmenu",children:f},b.menuCfg)});delete b.menuCfg;g=(new h(d.mix(b,i))).render();if(c=a.attr("name")){var k=(new e("<input type='hidden' name='"+c+"' value='"+j+"'>")).insertBefore(a,l);g.on("afterValueChange",function(a){k.val(a.newVal||"")})}a.remove();return g}},{xclass:"select",priority:30});return h},{requires:["node","./base","menu","./option"]});
