_Contained.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /*
  2. Copyright (c) 2004-2012, The Dojo Foundation All Rights Reserved.
  3. Available via Academic Free License >= 2.1 OR the modified BSD license.
  4. see: http://dojotoolkit.org/license for details
  5. */
  6. if(!dojo._hasResource["dijit._Contained"]){ //_hasResource checks added by build. Do not use _hasResource directly in your code.
  7. dojo._hasResource["dijit._Contained"] = true;
  8. dojo.provide("dijit._Contained");
  9. dojo.declare("dijit._Contained",
  10. null,
  11. {
  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. // | dojo.declare("my.customClass",[dijit._Widget,dijit._Contained],{});
  18. getParent: function(){
  19. // summary:
  20. // Returns the parent widget of this widget, assuming the parent
  21. // specifies isContainer
  22. var parent = dijit.getEnclosingWidget(this.domNode.parentNode);
  23. return parent && parent.isContainer ? parent : null;
  24. },
  25. _getSibling: function(/*String*/ which){
  26. // summary:
  27. // Returns next or previous sibling
  28. // which:
  29. // Either "next" or "previous"
  30. // tags:
  31. // private
  32. var node = this.domNode;
  33. do{
  34. node = node[which+"Sibling"];
  35. }while(node && node.nodeType != 1);
  36. return node && dijit.byNode(node); // dijit._Widget
  37. },
  38. getPreviousSibling: function(){
  39. // summary:
  40. // Returns null if this is the first child of the parent,
  41. // otherwise returns the next element sibling to the "left".
  42. return this._getSibling("previous"); // dijit._Widget
  43. },
  44. getNextSibling: function(){
  45. // summary:
  46. // Returns null if this is the last child of the parent,
  47. // otherwise returns the next element sibling to the "right".
  48. return this._getSibling("next"); // dijit._Widget
  49. },
  50. getIndexInParent: function(){
  51. // summary:
  52. // Returns the index of this widget within its container parent.
  53. // It returns -1 if the parent does not exist, or if the parent
  54. // is not a dijit._Container
  55. var p = this.getParent();
  56. if(!p || !p.getIndexOfChild){
  57. return -1; // int
  58. }
  59. return p.getIndexOfChild(this); // int
  60. }
  61. }
  62. );
  63. }