/*
Copyright 2013, KISSY UI Library v1.31
MIT Licensed
build time: Jan 15 13:39
*/
KISSY.add("tabs/bar",function(d,b){var a=b.extend({createDom:function(){this.get("el").attr("role","tablist")},handleKeyEventInternal:function(a){var c=this.get("selectedTab"),a=this.getNextItemByKeyEventInternal(a,c);if(d.isBoolean(a))return a;a.set("selected",!0);return!0},renderUI:function(){var a=this,c=a.get("children");d.each(c,function(c){c.get("selected")&&a.set("selectedTab",c)})},_onSetSelectedTab:function(a,c){var b;a&&(c&&(b=c.prevVal)&&b.set("selected",!1),a.set("selected",!0))},_onSetHighlightedItem:function(){a.superclass._onSetHighlightedItem.apply(this,
arguments);"mouse"==this.get("changeType")&&this._onSetSelectedTab.apply(this,arguments)},bindUI:function(){var a=this;a.on("afterSelectedChange",function(c){c.newVal&&c.target.isTabsTab&&a.set("selectedTab",c.target)})}},{ATTRS:{selectedTab:{},changeType:{value:"click"},defaultChildXClass:{value:"tabs-tab"}}},{xclass:"tabs-bar",priority:30});a.ChangeType={CLICK:"click",MOUSE:"mouse"};return a},{requires:["toolbar"]});
KISSY.add("tabs/body",function(d,b){return b.Container.extend({renderUI:function(){var a=this,b=a.get("children");d.each(b,function(b){b.get("selected")&&a.set("selectedPanel",b)})},bindUI:function(){this.on("afterSelectedPanelChange",function(a){a.newVal&&(a.prevVal&&a.prevVal.set("selected",!1),a.newVal.set("selected",!0))})}},{ATTRS:{selectedPanel:{},allowTextSelection:{value:!0},focusable:{value:!1},handleMouseEvents:{value:!1},delegateChildren:{value:!1},defaultChildXClass:{value:"tabs-panel"}}},
{xclass:"tabs-body"})},{requires:["component/base"]});
KISSY.add("tabs/panel-render",function(d,b){return b.Render.extend({createDom:function(){this.get("el").attr("role","tabpanel")},_onSetSelected:function(a){var b=this.get("el");b[a?"addClass":"removeClass"](this.get("selectedCls"));b.attr("aria-hidden",!a)}},{ATTRS:{selected:{value:!1},selectedCls:{valueFn:function(){return this.get("prefixCls")+"tabs-panel-selected"}}},HTML_PARSER:{selected:function(a){return a.hasClass(this.get("selectedCls"))}}})},{requires:["component/base"]});
KISSY.add("tabs/panel",function(d,b,a){return b.Controller.extend({},{ATTRS:{selected:{view:1},focusable:{value:!1},allowTextSelection:{value:!0},selectedCls:{view:1},xrender:{value:a}}},{xclass:"tabs-panel"})},{requires:["component/base","./panel-render"]});
KISSY.add("tabs/render",function(d,b){return b.Render.extend({_onSetBarOrientation:function(a){this.get("el").removeClass(this.getCssClassWithPrefix("tabs-top tabs-bottom tabs-left tabs-right")).addClass(this.getCssClassWithPrefix("tabs-"+a))}},{ATTRS:{barOrientation:{value:"top"}},HTML_PARSER:{barOrientation:function(a){return(a=a[0].className.match(/tabs-(top|bottom|left|right)\b/))&&a[1]||"top"}}})},{requires:["component/base"]});
KISSY.add("tabs/tab-render",function(d,b){return b.Render.extend({createDom:function(){this.get("el").attr("role","tab")},_onSetSelected:function(a){var b=this.get("el");b[a?"addClass":"removeClass"](this.get("selectedCls"));b.attr("aria-selected",!!a)}},{ATTRS:{selected:{value:!1},selectedCls:{valueFn:function(){return this.get("prefixCls")+"tabs-tab-selected"}}},HTML_PARSER:{selected:function(a){return a.hasClass(this.get("selectedCls"))}}})},{requires:["button"]});
KISSY.add("tabs/tab",function(d,b,a){return b.extend({isTabsTab:!0,bindUI:function(){this.on("click",function(){this.set("selected",!0)})}},{ATTRS:{handleMouseEvents:{value:!1},focusable:{value:!1},selected:{view:1},selectedCls:{view:1},xrender:{value:a}}},{xclass:"tabs-tab",priority:30})},{requires:["button","./tab-render"]});
KISSY.add("tabs",function(d,b,a,f,c,i,j){c=b.Controller.extend({initializer:function(){var k,a,e=this.get("prefixCls"),b=this.get("tabSelectedCls"),c=this.get("panelSelectedCls"),h,g,m={prefixCls:e,xclass:"tabs-bar",changeType:this.get("changeType"),children:[]},e={prefixCls:e,xclass:"tabs-body",children:[]},l=m.children,f=e.children;(a=this.get("items"))&&d.each(a,function(a){k=k||a.selected;l.push(h={content:a.title,selected:a.selected});f.push(g={content:a.content,selected:a.selected});b&&(h.selectedCls=
b);c&&(g.selectedCls=c)});!k&&l.length&&(l[0].selected=!0,f[0].selected=!0);this.set("bar",m);this.set("body",e)},addItem:function(a,b){var e=this.get("bar"),c,d;c=this.get("tabSelectedCls");var h=this.get("panelSelectedCls"),g,f=this.get("body");g={content:a.title};d={content:a.content};c&&(g.selectedCls=c);h&&(d.selectedCls=h);c=e.addChild(g,b);d=f.addChild(d,b);a.selected&&(e.set("selectedTab",c),f.set("selectedPanel",d));return this},removeItemAt:function(a,b){var e=this.get("bar"),c=e.get("children"),
d=e.getChildAt(a),f=this.get("body");d.get("selected")&&(1==c.length?e.set("selectedTab",null):0==a?e.set("selectedTab",e.getChildAt(a+1)):e.set("selectedTab",e.getChildAt(a-1)));e.removeChild(e.getChildAt(a),b);f.removeChild(f.getChildAt(a),b);return this},removeItemByTab:function(a,b){return this.removeItemAt(d.indexOf(a,this.get("bar").get("children")),b)},removeItemByPanel:function(a,b){return this.removeItemAt(d.indexOf(a,this.get("body").get("children")),b)},getSelectedTab:function(){var a=
this.get("bar"),b=null;d.each(a.get("children"),function(a){if(a.get("selected"))return b=a,!1});return b},getSelectedPanel:function(){var a=this.get("body"),b=null;d.each(a.get("children"),function(a){if(a.get("selected"))return b=a,!1});return b},getTabs:function(){return this.get("bar").get("children")},getPanels:function(){return this.get("body").get("children")},getTabAt:function(a){return this.get("bar").get("children")[a]},getPanelAt:function(a){return this.get("body").get("children")[a]},
setSelectedTab:function(a){var b=this.get("bar"),c=this.get("body");b.set("selectedTab",a);c.set("selectedPanel",this.getPanelAt(d.indexOf(a,b.get("children"))));return this},setSelectedPanel:function(a){var b=this.get("bar"),c=this.get("body");b.set("selectedPanel",a);c.set("selectedTab",this.getTabAt(d.indexOf(a,c.get("children"))));return this},renderUI:function(){var a=this.get("barOrientation"),b=this.get("el"),c=this.get("body"),d=this.get("bar");d.set("render",b);c.set("render",b);"bottom"==
a?(c.render(),d.render()):(d.render(),c.render())},decorateInternal:function(b){var c=this.get("prefixCls"),d=this.get("changeType"),i=b.children("."+c+"tabs-bar"),j=b.children("."+c+"tabs-body");this.set("el",b);this.set("bar",new a({srcNode:i,changeType:d,prefixCls:c}));this.set("body",new f({srcNode:j,changeType:d,prefixCls:c}))},bindUI:function(){this.on("afterSelectedTabChange",function(a){this.setSelectedTab(a.newVal)})}},{ATTRS:{items:{},changeType:{},tabSelectedCls:{},panelSelectedCls:{},
handleMouseEvents:{value:!1},allowTextSelection:{value:!0},focusable:{value:!1},bar:{setter:function(a){a&&!a.isController&&(a=b.create(a,this));a&&a.addTarget(this);return a},valueFn:function(){return b.create({xclass:"tabs-bar",prefixCls:this.get("prefixCls")})}},body:{setter:function(a){if(a&&!a.isController)return b.create(a,this)},valueFn:function(){return b.create({xclass:"tabs-body",prefixCls:this.get("prefixCls")})}},barOrientation:{view:1},xrender:{value:j}}},{xclass:"tabs"});c.Orientation=
{TOP:"top",BOTTOM:"bottom",LEFT:"left",RIGHT:"right"};c.ChangeType=a.ChangeType;c.Bar=a;c.Body=f;c.Panel=i;return c},{requires:"component/base,tabs/bar,tabs/body,tabs/tab,tabs/panel,tabs/render".split(",")});
