_Contained.js.uncompressed.js 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. return declare("dijit._Contained", null, {
  8. // summary:
  9. // Mixin for widgets that are children of a container widget
  10. //
  11. // example:
  12. // | // make a basic custom widget that knows about it's parents
  13. // | declare("my.customClass",[dijit._Widget,dijit._Contained],{});
  14. _getSibling: function(/*String*/ which){
  15. // summary:
  16. // Returns next or previous sibling
  17. // which:
  18. // Either "next" or "previous"
  19. // tags:
  20. // private
  21. var node = this.domNode;
  22. do{
  23. node = node[which+"Sibling"];
  24. }while(node && node.nodeType != 1);
  25. return node && registry.byNode(node); // dijit/_WidgetBase
  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. return this._getSibling("previous"); // dijit/_WidgetBase
  32. },
  33. getNextSibling: function(){
  34. // summary:
  35. // Returns null if this is the last child of the parent,
  36. // otherwise returns the next element sibling to the "right".
  37. return this._getSibling("next"); // dijit/_WidgetBase
  38. },
  39. getIndexInParent: function(){
  40. // summary:
  41. // Returns the index of this widget within its container parent.
  42. // It returns -1 if the parent does not exist, or if the parent
  43. // is not a dijit._Container
  44. var p = this.getParent();
  45. if(!p || !p.getIndexOfChild){
  46. return -1; // int
  47. }
  48. return p.getIndexOfChild(this); // int
  49. }
  50. });
  51. });