BorderContainer.js 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134
  1. if (!dojo._hasResource["dojox.layout.BorderContainer"]) { // _hasResource
  2. // checks added by
  3. // build. Do not use
  4. // _hasResource
  5. // directly in your
  6. // code.
  7. dojo._hasResource["dojox.layout.BorderContainer"] = true;
  8. dojo.provide("dojox.layout.BorderContainer");
  9. dojo.require("dijit.layout._LayoutWidget");
  10. dojo.experimental("dojox.layout.BorderContainer");
  11. dojo.declare("dojox.layout.BorderContainer",
  12. // [dijit._Widget, dijit._Container, dijit._Contained],
  13. dijit.layout._LayoutWidget, {
  14. // summary
  15. // Provides layout in 5 regions, a center and borders along its
  16. // 4 sides.
  17. //
  18. // details
  19. // A BorderContainer is a box with a specified size (like
  20. // style="width: 500px; height: 500px;"),
  21. // that contains children widgets marked with "position" of
  22. // "top", "bottom", "left", "right", "center".
  23. // It takes it's children marked as top/bottom/left/right, and
  24. // lays them out along the edges of the center box,
  25. // with "top" and "bottom" extending the full width of the
  26. // container.
  27. //
  28. // usage
  29. // <style>
  30. // html, body{ height: 100%; width: 100%; }
  31. // </style>
  32. // <div dojoType="BorderContainer" style="width: 100%; height:
  33. // 100%">
  34. // <div dojoType="ContentPane" position="top">header text</div>
  35. // <div dojoType="ContentPane" position="right" style="width:
  36. // 200px;">table of contents</div>
  37. // <div dojoType="ContentPane" position="center">client
  38. // area</div>
  39. // </div>
  40. top : {},
  41. bottom : {},
  42. left : {}, // inside?
  43. right : {}, // outside?
  44. center : {},
  45. layout : function() {
  46. this._layoutChildren(this.domNode, this._contentBox, this
  47. .getChildren());
  48. },
  49. addChild : function(/* Widget */child, /* Integer? */insertIndex) {
  50. dijit._Container.prototype.addChild.apply(this, arguments);
  51. if (this._started) {
  52. this._layoutChildren(this.domNode, this._contentBox,
  53. this.getChildren());
  54. }
  55. },
  56. removeChild : function(/* Widget */widget) {
  57. dijit._Container.prototype.removeChild.apply(this,
  58. arguments);
  59. if (this._started) {
  60. this._layoutChildren(this.domNode, this._contentBox,
  61. this.getChildren());
  62. }
  63. },
  64. _layoutChildren : function(/* DomNode */container, /* Object */
  65. dim, /* Object[] */children) {
  66. /**
  67. * summary Layout a bunch of child dom nodes within a parent
  68. * dom node container: parent node dim: {l, t, w, h} object
  69. * specifying dimensions of container into which to place
  70. * children children: an array like [ {domNode: foo,
  71. * position: "bottom" }, {domNode: bar, position: "client"} ]
  72. */
  73. // TODO: what is dim and why doesn't it look right?
  74. // copy dim because we are going to modify it
  75. // dim = dojo.mixin({}, dim);
  76. this.domNode.style.position = "relative";
  77. // FIXME: do this once? somewhere else?
  78. dojo.addClass(container, "dijitBorderContainer");
  79. dojo.forEach(children, function(child) {
  80. var style = child.domNode.style;
  81. style.position = "absolute";
  82. if (child.position) {
  83. this[child.position] = child.domNode;
  84. }
  85. }, this);
  86. var topStyle = this.top.style;
  87. var rightStyle = this.right.style;
  88. var leftStyle = this.left.style;
  89. var centerStyle = this.center.style;
  90. var bottomStyle = this.bottom.style;
  91. var rightCoords = dojo.coords(this.right);
  92. var leftCoords = dojo.coords(this.left);
  93. var centerCoords = dojo.coords(this.center);
  94. var bottomCoords = dojo.coords(this.bottom);
  95. var topCoords = dojo.coords(this.top);
  96. rightStyle.top = leftStyle.top = centerStyle.top = topCoords.h
  97. + "px";
  98. topStyle.top = topStyle.left = topStyle.right = "0px";
  99. bottomStyle.left = bottomStyle.bottom = bottomStyle.right = "0px";
  100. leftStyle.left = rightStyle.right = "0px";
  101. centerStyle.left = leftCoords.w + "px";
  102. centerStyle.right = rightCoords.w + "px";
  103. rightStyle.bottom = leftStyle.bottom = centerStyle.bottom = bottomCoords.h
  104. + "px";
  105. },
  106. resize : function(args) {
  107. this.layout();
  108. }
  109. });
  110. // This argument can be specified for the children of a BorderContainer.
  111. // Since any widget can be specified as a LayoutContainer child, mix it
  112. // into the base widget class. (This is a hack, but it's effective.)
  113. dojo.extend(dijit._Widget, {
  114. // position: String
  115. // "top", "bottom", "left", "right", "center".
  116. // See the BorderContainer description for details on this
  117. // parameter.
  118. position : 'none'
  119. });
  120. }