FixedSplitter.js 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. define("dojox/mobile/FixedSplitter", [
  2. "dojo/_base/array",
  3. "dojo/_base/declare",
  4. "dojo/_base/window",
  5. "dojo/dom-class",
  6. "dojo/dom-geometry",
  7. "dijit/_Contained",
  8. "dijit/_Container",
  9. "dijit/_WidgetBase",
  10. "./FixedSplitterPane"
  11. ], function(array, declare, win, domClass, domGeometry, Contained, Container, WidgetBase, FixedSplitterPane){
  12. /*=====
  13. var Contained = dijit._Contained;
  14. var Container = dijit._Container;
  15. var WidgetBase = dijit._WidgetBase;
  16. =====*/
  17. // module:
  18. // dojox/mobile/FixedSplitter
  19. // summary:
  20. // A layout container that splits the window horizontally or vertically.
  21. return declare("dojox.mobile.FixedSplitter", [WidgetBase, Container, Contained], {
  22. // summary:
  23. // A layout container that splits the window horizontally or
  24. // vertically.
  25. // description:
  26. // FixedSplitter is a very simple container widget that layouts its
  27. // child dom nodes side by side either horizontally or
  28. // vertically. An example usage of this widget would be to realize
  29. // the split view on iPad. There is no visual splitter between the
  30. // children, and there is no function to resize the child panes
  31. // with drag-and-drop. If you need a visual splitter, you can
  32. // specify a border of a child dom node with CSS.
  33. // A child of the widget should be FixedSplitterPane.
  34. //
  35. // example:
  36. // | <div dojoType="dojox.mobile.FixedSplitter" orientation="H">
  37. // | <div dojoType="dojox.mobile.FixedSplitterPane"
  38. // | style="width:200px;border-right:1px solid black;">
  39. // | pane #1 (width=200px)
  40. // | </div>
  41. // | <div dojoType="dojox.mobile.FixedSplitterPane">
  42. // | pane #2
  43. // | </div>
  44. // | </div>
  45. // orientation: String
  46. // The direction of split. If "H" is specified, panes are split
  47. // horizontally. If "V" is specified, panes are split vertically.
  48. orientation: "H",
  49. buildRendering: function(){
  50. this.domNode = this.containerNode = this.srcNodeRef ? this.srcNodeRef : win.doc.createElement("DIV");
  51. domClass.add(this.domNode, "mblFixedSpliter");
  52. },
  53. startup: function(){
  54. if(this._started){ return; }
  55. var children = array.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; });
  56. array.forEach(children, function(node){
  57. domClass.add(node, "mblFixedSplitterPane"+this.orientation);
  58. }, this);
  59. this.inherited(arguments);
  60. var _this = this;
  61. setTimeout(function(){
  62. var parent = _this.getParent && _this.getParent();
  63. if(!parent || !parent.resize){ // top level widget
  64. _this.resize();
  65. }
  66. }, 0);
  67. },
  68. resize: function(){
  69. this.layout();
  70. },
  71. layout: function(){
  72. var sz = this.orientation == "H" ? "w" : "h";
  73. var children = array.filter(this.domNode.childNodes, function(node){ return node.nodeType == 1; });
  74. var offset = 0;
  75. for(var i = 0; i < children.length; i++){
  76. domGeometry.setMarginBox(children[i], this.orientation == "H" ? {l:offset} : {t:offset});
  77. if(i < children.length - 1){
  78. offset += domGeometry.getMarginBox(children[i])[sz];
  79. }
  80. }
  81. var h;
  82. if(this.orientation == "V"){
  83. if(this.domNode.parentNode.tagName == "BODY"){
  84. if(array.filter(win.body().childNodes, function(node){ return node.nodeType == 1; }).length == 1){
  85. h = (win.global.innerHeight||win.doc.documentElement.clientHeight);
  86. }
  87. }
  88. }
  89. var l = (h || domGeometry.getMarginBox(this.domNode)[sz]) - offset;
  90. var props = {};
  91. props[sz] = l;
  92. domGeometry.setMarginBox(children[children.length - 1], props);
  93. array.forEach(this.getChildren(), function(child){
  94. if(child.resize){ child.resize(); }
  95. });
  96. },
  97. addChild: function(widget, /*Number?*/insertIndex){
  98. domClass.add(widget.domNode, "mblFixedSplitterPane"+this.orientation);
  99. this.inherited(arguments);
  100. }
  101. });
  102. });