/*
Copyright 2013, KISSY UI Library v1.31
MIT Licensed
build time: Apr 11 16:52
*/
KISSY.add("tree/base",function(g,d,c,f,a){return c.extend([a],{},{ATTRS:{xrender:{value:f},defaultChildXClass:{value:"tree-node"}}},{xclass:"tree",priority:30})},{requires:["component/base","./node","./tree-render","./tree-manager"]});
KISSY.add("tree/check-node-render",function(g,d,c){var f=d.all;return c.extend({createDom:function(){var a=this.get("expandIconEl");this.setInternal("checkIconEl",f("<div>").insertAfter(a))},_onSetCheckState:function(a){this.get("checkIconEl").removeClass(this.getCssClassWithPrefix("tree-node-checked0 tree-node-checked1 tree-node-checked2")).addClass(this.getCssClassWithPrefix("tree-node-checked")+a)}},{ATTRS:{checkIconEl:{},checkState:{value:0}}})},{requires:["node","./node-render"]});
KISSY.add("tree/check-node",function(g,d,c,f){var a=d.all,d=c.extend({performActionInternal:function(e){var b;b=this.get("expanded");var d=this.get("expandIconEl"),g=this.get("tree"),e=a(e.target);g.get("el")[0].focus();e.equals(d)?this.set("expanded",!b):(b=this.get("checkState"),this.set("checkState",1==b?0:1),this.fire("click"))},_onSetCheckState:function(a){var b=this.get("parent"),d,c,f,i;(1==a||0==a)&&g.each(this.get("children"),function(b){b.set("checkState",a)});if(b){d=0;i=b.get("children");
for(c=0;c<i.length;c++){f=i[c];f=f.get("checkState");if(2==f){b.set("checkState",2);return}1==f&&d++}0===d?b.set("checkState",0):d==i.length?b.set("checkState",1):b.set("checkState",2)}}},{ATTRS:{checkIconEl:{view:1},checkState:{view:1},xrender:{value:f},defaultChildXClass:{value:"check-tree-node"}}},{xclass:"check-tree-node",priority:20});g.mix(d,{PARTIAL_CHECK:2,CHECK:1,EMPTY:0});return d},{requires:["node","./node","./check-node-render"]});
KISSY.add("tree/check-tree-render",function(g,d,c){return d.extend([c])},{requires:["./check-node-render","./tree-manager-render"]});KISSY.add("tree/check-tree",function(g,d,c,f,a){return c.extend([a],{_onSetFocused:function(){}},{ATTRS:{xrender:{value:f},defaultChildXClass:{value:"check-tree-node"}}},{xclass:"check-tree",priority:40})},{requires:["component/base","./check-node","./check-tree-render","./tree-manager"]});
KISSY.add("tree/node-render",function(g,d,c){var f=d.all;return c.Render.extend({refreshCss:function(a,e){var b=this.get("expanded"),d=this.get("iconEl"),c,f=this.get("expandIconEl"),i=this.get("childrenEl");e?(b="tree-file-icon",c="tree-expand-icon-{t}"):b?(b="tree-expanded-folder-icon",c="tree-expand-icon-{t}minus"):(b="tree-collapsed-folder-icon",c="tree-expand-icon-{t}plus");d.attr("class",this.getCssClassWithPrefix(b));f.attr("class",this.getCssClassWithPrefix(g.substitute(c,{t:a?"l":"t"})));
i&&i.attr("class",this.getCssClassWithPrefix(a?"tree-lchildren":"tree-children"))},createDom:function(){var a=this.get("el"),e,b,d,c,k=this.get("contentEl");b=f("<div class='"+this.getCssClassWithPrefix("tree-node-row")+"'/>");(e=k.attr("id"))||k.attr("id",e=g.guid("ks-tree-node"));d=f("<div>").appendTo(b);c=f("<div>").appendTo(b);k.appendTo(b);a.attr({role:"tree-node","aria-labelledby":e}).prepend(b);this.setInternal("rowEl",b);this.setInternal("expandIconEl",d);this.setInternal("iconEl",c)},_onSetExpanded:function(a){var e=
this.get("childrenEl");if(e)e[a?"show":"hide"]();this.get("el").attr("aria-expanded",a)},_onSetSelected:function(a){this.get("rowEl")[a?"addClass":"removeClass"](this.getCssClassWithPrefix("tree-node-selected"));this.get("el").attr("aria-selected",a)},_onSetDepth:function(a){this.get("el").attr("aria-level",a)},_onSetTooltip:function(a){this.get("el").attr("title",a)},getContentElement:function(){var a;if(a=this.get("childrenEl"))return a;a=f("<div "+(this.get("expanded")?"":"style='display:none'")+
" role='group'></div>").appendTo(this.get("el"));this.setInternal("childrenEl",a);return a}},{ATTRS:{childrenEl:{},expandIconEl:{},tooltip:{},iconEl:{},expanded:{value:!1},rowEl:{},depth:{value:0},contentEl:{valueFn:function(){return f("<span id='"+g.guid("ks-tree-node")+"' class='"+this.getCssClassWithPrefix("tree-node-content")+"'/>")}},isLeaf:{},selected:{}},HTML_PARSER:{childrenEl:function(a){return a.children("."+this.getCssClassWithPrefix("tree-children"))},contentEl:function(a){return a.children("."+
this.getCssClassWithPrefix("tree-node-content"))},isLeaf:function(a){if(a.hasClass(this.getCssClassWithPrefix("tree-node-leaf")))return!0;if(a.hasClass(this.getCssClassWithPrefix("tree-node-folder")))return!1},expanded:function(a){a=a.one("."+this.get("prefixCls")+"tree-children");return!a?!1:"none"!=a.css("display")}}})},{requires:["node","component/base"]});
KISSY.add("tree/node",function(g,d,c,f){function a(h,j,e,b){h[e](j);void 0!==b&&j.set("depth",b);g.each(j.get("children"),function(j){j.isController&&(b?a(h,j,e,b+1):a(h,j,e))})}function e(h){var a=h.get("parent"),a=(a=a&&a.get("children"))&&a[a.length-1];return!a||a==h}function b(h){var a=h.get("isLeaf");return!(!1===a||void 0===a&&h.get("children").length)}function n(h){var a=h.get("children");return!h.get("expanded")||!a.length?h:n(a[a.length-1])}function m(h){h.get&&h.get("view")&&h.get("view").refreshCss(e(h),
b(h))}function k(h,a){var e=h.get("children"),b,d=e.length;m(h);a=Math.max(0,a-1);for(h.get("el")[0].setAttribute("aria-setsize",d);a<d;a++)b=e[a],b.get&&(m(b),b.get("el")[0].setAttribute("aria-posinset",a+1))}var i=d.all,l=d.KeyCodes,o=c.Container.extend([c.DecorateChild],{syncUI:function(){m(this)},_keyNav:function(a){var e=!0,b=this.get("tree"),d=this.get("expanded"),c,g=this.get("isLeaf"),f=this.get("children");switch(a.keyCode){case l.HOME:c=b;break;case l.END:c=n(b);break;case l.UP:c=a=(a=this.prev())?
n(a):this.get("parent");break;case l.DOWN:a=this.get("children");if(this.get("expanded")&&a.length)c=a[0];else{a=this.next();for(b=this;!a&&(b=b.get("parent"));)a=b.next();c=a}break;case l.LEFT:d&&(f.length||!1===g)?this.set("expanded",!1):c=this.get("parent");break;case l.RIGHT:if(f.length||!1===g)d?c=f[0]:this.set("expanded",!0);break;default:e=!1}c&&c.select();return e},next:function(){var a=this.get("parent"),b;if(!a)return null;a=a.get("children");b=g.indexOf(this,a);return b==a.length-1?null:
a[b+1]},prev:function(){var a=this.get("parent"),b;if(!a)return null;a=a.get("children");b=g.indexOf(this,a);return 0===b?null:a[b-1]},select:function(){this.get("tree").set("selectedItem",this)},performActionInternal:function(a){var a=i(a.target),b=this.get("expanded");this.get("tree").get("el")[0].focus();a.equals(this.get("expandIconEl"))?this.set("expanded",!b):(this.select(),this.fire("click"))},decorateChildrenInternal:function(a,b){this.addChild(new a({srcNode:b,prefixCls:this.get("prefixCls")}))},
addChild:function(b,e){void 0===e&&(e=this.get("children").length);var b=o.superclass.addChild.apply(this,g.makeArray(arguments)),c=this.get("tree");c&&(a(c,b,"_register",this.get("depth")+1),k(this,e));return b},removeChild:function(b){var e,c=this.get("tree");c&&(e=g.indexOf(b,this.get("children")),a(c,b,"_unRegister"),o.superclass.removeChild.apply(this,g.makeArray(arguments)),k(this,e));return b},_onSetExpanded:function(a){this.get("tree");this.get("rendered")&&(m(this),this.fire(a?"expand":"collapse"))},
expandAll:function(){this.set("expanded",!0);g.each(this.get("children"),function(a){a.expandAll()})},collapseAll:function(){this.set("expanded",!1);g.each(this.get("children"),function(a){a.collapseAll()})}},{ATTRS:{delegateChildren:{value:!1},xrender:{value:f},handleMouseEvents:{value:!1},isLeaf:{view:1},expandIconEl:{view:1},iconEl:{view:1},selected:{view:1},expanded:{view:1},collapsed:{getter:function(){return!this.get("expanded")},setter:function(a){this.set("expanded",!a)}},tooltip:{view:1},
tree:{getter:function(){for(var a=this;a&&!a.isTree;)a=a.get("parent");return a}},depth:{view:1},focusable:{value:!1},decorateChildCls:{valueFn:function(){return this.get("prefixCls")+"tree-children"}},defaultChildXClass:{value:"tree-node"}}},{xclass:"tree-node",priority:10});return o},{requires:["node","component/base","./node-render"]});
KISSY.add("tree/tree-manager-render",function(g){function d(){}d.ATTRS={showRootNode:{}};g.augment(d,{__renderUI:function(){this.get("el").attr("role","tree");this.get("rowEl").addClass(this.get("prefixCls")+"tree-row")},_onSetShowRootNode:function(c){this.get("rowEl")[c?"show":"hide"]()}});return d});
KISSY.add("tree/tree-manager",function(g,d){function c(){}function f(a){var a=a.get("el"),b=a.attr("id");b||a.attr("id",b=g.guid("tree-node"));return b}function a(a){a._allNodes||(a._allNodes={});return a._allNodes}c.ATTRS={delegateChildren:{value:!0},showRootNode:{value:!0,view:1},selectedItem:{},focusable:{value:!0}};g.augment(c,{isTree:1,_register:function(e){e.__isRegisted||(a(this)[f(e)]=e,e.__isRegisted=1)},_unRegister:function(e){e.__isRegisted&&(delete a(this)[f(e)],e.__isRegisted=0)},handleKeyEventInternal:function(a){var b=
this.get("selectedItem");return a.keyCode==d.KeyCodes.ENTER?b.performActionInternal(a):b._keyNav(a)},getOwnerControl:function(c){for(var b,d=a(this),f=this.get("el")[0];c&&c!==f;){if(b=d[c.id])return b;c=c.parentNode}return this},_onSetSelectedItem:function(a,b){b.prevVal&&b.prevVal.set("selected",!1);a.set("selected",!0)},_onSetFocused:function(a){a&&!this.get("selectedItem")&&this.select()}});return c},{requires:["event"]});
KISSY.add("tree/tree-render",function(g,d,c){return d.extend([c])},{requires:["./node-render","./tree-manager-render"]});KISSY.add("tree",function(g,d,c,f,a){d.Node=c;d.CheckNode=f;d.CheckTree=a;return d},{requires:["tree/base","tree/node","tree/check-node","tree/check-tree"]});
