source: Dev/branches/rest-dojo-ui/client/dijit/_Contained.js @ 274

Last change on this file since 274 was 256, checked in by hendrikvanantwerpen, 13 years ago

Reworked project structure based on REST interaction and Dojo library. As
soon as this is stable, the old jQueryUI branch can be removed (it's
kept for reference).

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