| 1 | define([ |
| 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 | // example: |
| 13 | // | // make a basic custom widget that knows about its parents |
| 14 | // | declare("my.customClass",[dijit._WidgetBase, dijit._Contained],{}); |
| 15 | |
| 16 | _getSibling: function(/*String*/ which){ |
| 17 | // summary: |
| 18 | // Returns next or previous sibling |
| 19 | // which: |
| 20 | // Either "next" or "previous" |
| 21 | // tags: |
| 22 | // private |
| 23 | var p = this.getParent(); |
| 24 | return (p && p._getSiblingOfChild && p._getSiblingOfChild(this, which == "previous" ? -1 : 1)) || null; // dijit/_WidgetBase |
| 25 | }, |
| 26 | |
| 27 | getPreviousSibling: function(){ |
| 28 | // summary: |
| 29 | // Returns null if this is the first child of the parent, |
| 30 | // otherwise returns the next element sibling to the "left". |
| 31 | |
| 32 | return this._getSibling("previous"); // dijit/_WidgetBase |
| 33 | }, |
| 34 | |
| 35 | getNextSibling: function(){ |
| 36 | // summary: |
| 37 | // Returns null if this is the last child of the parent, |
| 38 | // otherwise returns the next element sibling to the "right". |
| 39 | |
| 40 | return this._getSibling("next"); // dijit/_WidgetBase |
| 41 | }, |
| 42 | |
| 43 | getIndexInParent: function(){ |
| 44 | // summary: |
| 45 | // Returns the index of this widget within its container parent. |
| 46 | // It returns -1 if the parent does not exist, or if the parent |
| 47 | // is not a dijit/_Container |
| 48 | |
| 49 | var p = this.getParent(); |
| 50 | if(!p || !p.getIndexOfChild){ |
| 51 | return -1; // int |
| 52 | } |
| 53 | return p.getIndexOfChild(this); // int |
| 54 | } |
| 55 | }); |
| 56 | }); |