You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
95 lines
3.0 KiB
JavaScript
95 lines
3.0 KiB
JavaScript
define("dijit/_Container", [
|
|
"dojo/_base/array", // array.forEach array.indexOf
|
|
"dojo/_base/declare", // declare
|
|
"dojo/dom-construct" // domConstruct.place
|
|
], function(array, declare, domConstruct){
|
|
|
|
// module:
|
|
// dijit/_Container
|
|
|
|
return declare("dijit._Container", null, {
|
|
// summary:
|
|
// Mixin for widgets that contain HTML and/or a set of widget children.
|
|
|
|
buildRendering: function(){
|
|
this.inherited(arguments);
|
|
if(!this.containerNode){
|
|
// all widgets with descendants must set containerNode
|
|
this.containerNode = this.domNode;
|
|
}
|
|
},
|
|
|
|
addChild: function(/*dijit/_WidgetBase*/ widget, /*int?*/ insertIndex){
|
|
// summary:
|
|
// Makes the given widget a child of this widget.
|
|
// description:
|
|
// Inserts specified child widget's dom node as a child of this widget's
|
|
// container node, and possibly does other processing (such as layout).
|
|
//
|
|
// Functionality is undefined if this widget contains anything besides
|
|
// a list of child widgets (ie, if it contains arbitrary non-widget HTML).
|
|
|
|
var refNode = this.containerNode;
|
|
if(insertIndex && typeof insertIndex == "number"){
|
|
var children = this.getChildren();
|
|
if(children && children.length >= insertIndex){
|
|
refNode = children[insertIndex-1].domNode;
|
|
insertIndex = "after";
|
|
}
|
|
}
|
|
domConstruct.place(widget.domNode, refNode, insertIndex);
|
|
|
|
// If I've been started but the child widget hasn't been started,
|
|
// start it now. Make sure to do this after widget has been
|
|
// inserted into the DOM tree, so it can see that it's being controlled by me,
|
|
// so it doesn't try to size itself.
|
|
if(this._started && !widget._started){
|
|
widget.startup();
|
|
}
|
|
},
|
|
|
|
removeChild: function(/*Widget|int*/ widget){
|
|
// summary:
|
|
// Removes the passed widget instance from this widget but does
|
|
// not destroy it. You can also pass in an integer indicating
|
|
// the index within the container to remove (ie, removeChild(5) removes the sixth widget).
|
|
|
|
if(typeof widget == "number"){
|
|
widget = this.getChildren()[widget];
|
|
}
|
|
|
|
if(widget){
|
|
var node = widget.domNode;
|
|
if(node && node.parentNode){
|
|
node.parentNode.removeChild(node); // detach but don't destroy
|
|
}
|
|
}
|
|
},
|
|
|
|
hasChildren: function(){
|
|
// summary:
|
|
// Returns true if widget has child widgets, i.e. if this.containerNode contains widgets.
|
|
return this.getChildren().length > 0; // Boolean
|
|
},
|
|
|
|
_getSiblingOfChild: function(/*dijit/_WidgetBase*/ child, /*int*/ dir){
|
|
// summary:
|
|
// Get the next or previous widget sibling of child
|
|
// dir:
|
|
// if 1, get the next sibling
|
|
// if -1, get the previous sibling
|
|
// tags:
|
|
// private
|
|
var children = this.getChildren(),
|
|
idx = array.indexOf(this.getChildren(), child); // int
|
|
return children[idx + dir];
|
|
},
|
|
|
|
getIndexOfChild: function(/*dijit/_WidgetBase*/ child){
|
|
// summary:
|
|
// Gets the index of the child in this container or -1 if not found
|
|
return array.indexOf(this.getChildren(), child); // int
|
|
}
|
|
});
|
|
});
|