]>
Commit | Line | Data |
---|---|---|
f0cfe83e AD |
1 | define("dijit/_Contained", [ |
2 | "dojo/_base/declare", // declare | |
3 | "./registry" // registry.getEnclosingWidget(), registry.byNode() | |
4 | ], function(declare, registry){ | |
5 | ||
6 | // module: | |
7 | // dijit/_Contained | |
8 | ||
9 | return declare("dijit._Contained", null, { | |
10 | // summary: | |
11 | // Mixin for widgets that are children of a container widget | |
12 | // | |
13 | // example: | |
14 | // | // make a basic custom widget that knows about it's parents | |
15 | // | declare("my.customClass",[dijit._Widget,dijit._Contained],{}); | |
16 | ||
17 | _getSibling: function(/*String*/ which){ | |
18 | // summary: | |
19 | // Returns next or previous sibling | |
20 | // which: | |
21 | // Either "next" or "previous" | |
22 | // tags: | |
23 | // private | |
24 | var node = this.domNode; | |
25 | do{ | |
26 | node = node[which+"Sibling"]; | |
27 | }while(node && node.nodeType != 1); | |
28 | return node && registry.byNode(node); // dijit/_WidgetBase | |
29 | }, | |
30 | ||
31 | getPreviousSibling: function(){ | |
32 | // summary: | |
33 | // Returns null if this is the first child of the parent, | |
34 | // otherwise returns the next element sibling to the "left". | |
35 | ||
36 | return this._getSibling("previous"); // dijit/_WidgetBase | |
37 | }, | |
38 | ||
39 | getNextSibling: function(){ | |
40 | // summary: | |
41 | // Returns null if this is the last child of the parent, | |
42 | // otherwise returns the next element sibling to the "right". | |
43 | ||
44 | return this._getSibling("next"); // dijit/_WidgetBase | |
45 | }, | |
46 | ||
47 | getIndexInParent: function(){ | |
48 | // summary: | |
49 | // Returns the index of this widget within its container parent. | |
50 | // It returns -1 if the parent does not exist, or if the parent | |
51 | // is not a dijit._Container | |
52 | ||
53 | var p = this.getParent(); | |
54 | if(!p || !p.getIndexOfChild){ | |
55 | return -1; // int | |
56 | } | |
57 | return p.getIndexOfChild(this); // int | |
58 | } | |
59 | }); | |
60 | }); |