_Contained.js 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. define("dijit/_Contained", [
  2. "dojo/_base/declare", // declare
  3. "./registry" // registry.getEnclosingWidget(), registry.byNode()
  4. ], function(declare, registry){
  5. // module:
  6. // dijit/_Contained
  7. // summary:
  8. // Mixin for widgets that are children of a container widget
  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. _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 node = this.domNode;
  24. do{
  25. node = node[which+"Sibling"];
  26. }while(node && node.nodeType != 1);
  27. return node && registry.byNode(node); // dijit._Widget
  28. },
  29. getPreviousSibling: function(){
  30. // summary:
  31. // Returns null if this is the first child of the parent,
  32. // otherwise returns the next element sibling to the "left".
  33. return this._getSibling("previous"); // dijit._Widget
  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. return this._getSibling("next"); // dijit._Widget
  40. },
  41. getIndexInParent: function(){
  42. // summary:
  43. // Returns the index of this widget within its container parent.
  44. // It returns -1 if the parent does not exist, or if the parent
  45. // is not a dijit._Container
  46. var p = this.getParent();
  47. if(!p || !p.getIndexOfChild){
  48. return -1; // int
  49. }
  50. return p.getIndexOfChild(this); // int
  51. }
  52. });
  53. });