]> git.wh0rd.org Git - tt-rss.git/blob - lib/dijit/_Container.js.uncompressed.js
upgrade dojo to 1.8.3 (refs #570)
[tt-rss.git] / lib / dijit / _Container.js.uncompressed.js
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){
6
7         // module:
8         //              dijit/_Container
9
10         return declare("dijit._Container", null, {
11                 // summary:
12                 //              Mixin for widgets that contain HTML and/or a set of widget children.
13
14                 buildRendering: function(){
15                         this.inherited(arguments);
16                         if(!this.containerNode){
17                                 // all widgets with descendants must set containerNode
18                                 this.containerNode = this.domNode;
19                         }
20                 },
21
22                 addChild: function(/*dijit/_WidgetBase*/ widget, /*int?*/ insertIndex){
23                         // summary:
24                         //              Makes the given widget a child of this widget.
25                         // description:
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).
28                         //
29                         //              Functionality is undefined if this widget contains anything besides
30                         //              a list of child widgets (ie, if it contains arbitrary non-widget HTML).
31
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";
38                                 }
39                         }
40                         domConstruct.place(widget.domNode, refNode, insertIndex);
41
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){
47                                 widget.startup();
48                         }
49                 },
50
51                 removeChild: function(/*Widget|int*/ widget){
52                         // summary:
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).
56
57                         if(typeof widget == "number"){
58                                 widget = this.getChildren()[widget];
59                         }
60
61                         if(widget){
62                                 var node = widget.domNode;
63                                 if(node && node.parentNode){
64                                         node.parentNode.removeChild(node); // detach but don't destroy
65                                 }
66                         }
67                 },
68
69                 hasChildren: function(){
70                         // summary:
71                         //              Returns true if widget has child widgets, i.e. if this.containerNode contains widgets.
72                         return this.getChildren().length > 0;   // Boolean
73                 },
74
75                 _getSiblingOfChild: function(/*dijit/_WidgetBase*/ child, /*int*/ dir){
76                         // summary:
77                         //              Get the next or previous widget sibling of child
78                         // dir:
79                         //              if 1, get the next sibling
80                         //              if -1, get the previous sibling
81                         // tags:
82                         //              private
83                         var children = this.getChildren(),
84                                 idx = array.indexOf(this.getChildren(), child); // int
85                         return children[idx + dir];
86                 },
87
88                 getIndexOfChild: function(/*dijit/_WidgetBase*/ child){
89                         // summary:
90                         //              Gets the index of the child in this container or -1 if not found
91                         return array.indexOf(this.getChildren(), child);        // int
92                 }
93         });
94 });