widget-parent-min.js revision 5ade5e81a333bf99e7eb5c1347fcb3d2de2d1e9b
YUI.add("widget-parent",function(C){var B=C.Lang;function A(){}A.ATTRS={defaultChildType:{},activeItem:{readOnly:true},multiple:{value:false,validator:B.isBoolean,writeOnce:true},selection:{readOnly:true,setter:"_setSelection"},children:{value:[],readOnly:true,getter:function(D){return D.concat();}}};A.prototype={_afterSelectionChange:function(F){if(F.target==this){var D=F.newVal,E=0;if(D){E=1;if(B.isArray(D)&&(D.length<this.get("children").length)){E=2;}}this.set("selected",E,{src:this});}},_afterParentSelectedChange:function(E){var F=E.newVal,D=this.get("children");if(this==E.target&&E.src!=this&&D.length>0&&(F===0||F===1)){C.each(D,function(G){G.set("selected",F,{src:this});},this);}},_setSelection:function(G){var F=null,E=this.get("children"),D=this.get("root")||this;if(D.get("multiple")&&E.length>0){F=[];C.each(E,function(H){if(H.get("selected")>0){F.push(H);}});}else{if(G.get("selected")>0){F=G;}}return F;},_updateSelection:function(F){var G=F.target,E=this.get("selection"),D=this.get("root")||this;if(F.src!=this){if(!D.get("multiple")&&E&&F.newVal>0){E.set("selected",0,{src:this});}this._set("selection",G);}},_updateActiveItem:function(D){var E=null;if(D.newVal===true){E=D.target;}this._set("activeItem",E);},_createChild:function(D){var E=D.type||this.get("defaultChildType"),G,F;if(E){if(B.isString(E)){F=C[E];}else{if(B.isFunction(E)){F=E;}}}if(F){G=new F(D);}else{C.error("Could not create a child instance using the supplied type.");}return G;},_defChildAdded:function(F){var G=F.child,D=F.index,E=this.get("children");if(G.get("parent")){G.remove();}if(B.isNumber(D)){E.splice(D,0,G);}else{E.push(G);}this._set("children",E);G._set("parent",this);G.addTarget(this);if(G.get("selected")){this._set("selection",G);}G.after("selectedChange",C.bind(this._updateSelection,this));G.after("focusedChange",C.bind(this._updateActiveItem,this));},_defChildRemoved:function(F){var G=F.child,D=F.index,E=this.get("children");if(G.get("focused")){G.set("focused",false);}if(G.get("selected")){G.set("selected",0);}E.splice(D,1);this._set("children",E);G.removeTarget(this);G._set("parent",null);},add:function(H,D){var G,F,E;if(B.isArray(H)){G=[];C.each(H,function(I){F=this.add(I);if(F){G.push(F);}},this);if(G.length>0){E=G;}}else{if(H instanceof C.Widget){F=H;}else{F=this._createChild(H);}if(F&&this.fire("childAdded",{child:F,index:D})){E=F;}}return E;},remove:function(D){var F=this.get("children")[D],E;if(F&&this.fire("childRemoved",{child:F,index:D})){E=F;}return E;},removeAll:function(){var D=[],E,F;C.each(this.get("children"),function(H,G){F=this.remove(G);if(F){D.push(F);}});if(D.length>0){E=D;}return E;},item:function(D){return this.get("children")[D];},_renderUIParent:function(){var D=this.get("contentBox");C.each(this.get("children"),function(E){E.render(D);});},initializer:function(D){this.publish("childAdded",{defaultFn:this._defChildAdded});this.publish("childRemoved",{defaultFn:this._defChildRemoved});if(D&&D.children){this.add(D.children);}C.after(this._renderUIParent,this,"renderUI");this.after("selectionChange",this._afterSelectionChange);this.after("selectedChange",this._afterParentSelectedChange);}};C.WidgetParent=A;},"@VERSION@",{requires:["widget"]});