1 define("dijit/_Container", [
2 "dojo/_base/array", // array.forEach array.indexOf
3 "dojo/_base/declare", // declare
4 "dojo/dom-construct" // domConstruct.place
5 ], function(array, declare, domConstruct){
10 return declare("dijit._Container", null, {
12 // Mixin for widgets that contain HTML and/or a set of widget children.
14 buildRendering: function(){
15 this.inherited(arguments);
16 if(!this.containerNode){
17 // all widgets with descendants must set containerNode
18 this.containerNode = this.domNode;
22 addChild: function(/*dijit/_WidgetBase*/ widget, /*int?*/ insertIndex){
24 // Makes the given widget a child of this widget.
26 // Inserts specified child widget's dom node as a child of this widget's
27 // container node, and possibly does other processing (such as layout).
29 // Functionality is undefined if this widget contains anything besides
30 // a list of child widgets (ie, if it contains arbitrary non-widget HTML).
32 var refNode = this.containerNode;
33 if(insertIndex && typeof insertIndex == "number"){
34 var children = this.getChildren();
35 if(children && children.length >= insertIndex){
36 refNode = children[insertIndex-1].domNode;
37 insertIndex = "after";
40 domConstruct.place(widget.domNode, refNode, insertIndex);
42 // If I've been started but the child widget hasn't been started,
43 // start it now. Make sure to do this after widget has been
44 // inserted into the DOM tree, so it can see that it's being controlled by me,
45 // so it doesn't try to size itself.
46 if(this._started && !widget._started){
51 removeChild: function(/*Widget|int*/ widget){
53 // Removes the passed widget instance from this widget but does
54 // not destroy it. You can also pass in an integer indicating
55 // the index within the container to remove (ie, removeChild(5) removes the sixth widget).
57 if(typeof widget == "number"){
58 widget = this.getChildren()[widget];
62 var node = widget.domNode;
63 if(node && node.parentNode){
64 node.parentNode.removeChild(node); // detach but don't destroy
69 hasChildren: function(){
71 // Returns true if widget has child widgets, i.e. if this.containerNode contains widgets.
72 return this.getChildren().length > 0; // Boolean
75 _getSiblingOfChild: function(/*dijit/_WidgetBase*/ child, /*int*/ dir){
77 // Get the next or previous widget sibling of child
79 // if 1, get the next sibling
80 // if -1, get the previous sibling
83 var children = this.getChildren(),
84 idx = array.indexOf(this.getChildren(), child); // int
85 return children[idx + dir];
88 getIndexOfChild: function(/*dijit/_WidgetBase*/ child){
90 // Gets the index of the child in this container or -1 if not found
91 return array.indexOf(this.getChildren(), child); // int