You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

190 lines
7.5 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. <!DOCTYPE html>
  2. <html>
  3. <head>
  4. <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
  5. <title>The source code</title>
  6. <link href="../resources/prettify/prettify.css" type="text/css" rel="stylesheet" />
  7. <script type="text/javascript" src="../resources/prettify/prettify.js"></script>
  8. <style type="text/css">
  9. .highlight { display: block; background-color: #ddd; }
  10. </style>
  11. <script type="text/javascript">
  12. function highlight() {
  13. document.getElementById(location.hash.replace(/#/, "")).className = "highlight";
  14. }
  15. </script>
  16. </head>
  17. <body onload="prettyPrint(); highlight();">
  18. <pre class="prettyprint lang-js"><span id='Ext-layout-ColumnLayout'>/**
  19. </span> * @class Ext.layout.ColumnLayout
  20. * @extends Ext.layout.ContainerLayout
  21. * &lt;p&gt;This is the layout style of choice for creating structural layouts in a multi-column format where the width of
  22. * each column can be specified as a percentage or fixed width, but the height is allowed to vary based on the content.
  23. * This class is intended to be extended or created via the layout:'column' {@link Ext.Container#layout} config,
  24. * and should generally not need to be created directly via the new keyword.&lt;/p&gt;
  25. * &lt;p&gt;ColumnLayout does not have any direct config options (other than inherited ones), but it does support a
  26. * specific config property of &lt;b&gt;&lt;tt&gt;columnWidth&lt;/tt&gt;&lt;/b&gt; that can be included in the config of any panel added to it. The
  27. * layout will use the columnWidth (if present) or width of each panel during layout to determine how to size each panel.
  28. * If width or columnWidth is not specified for a given panel, its width will default to the panel's width (or auto).&lt;/p&gt;
  29. * &lt;p&gt;The width property is always evaluated as pixels, and must be a number greater than or equal to 1.
  30. * The columnWidth property is always evaluated as a percentage, and must be a decimal value greater than 0 and
  31. * less than 1 (e.g., .25).&lt;/p&gt;
  32. * &lt;p&gt;The basic rules for specifying column widths are pretty simple. The logic makes two passes through the
  33. * set of contained panels. During the first layout pass, all panels that either have a fixed width or none
  34. * specified (auto) are skipped, but their widths are subtracted from the overall container width. During the second
  35. * pass, all panels with columnWidths are assigned pixel widths in proportion to their percentages based on
  36. * the total &lt;b&gt;remaining&lt;/b&gt; container width. In other words, percentage width panels are designed to fill the space
  37. * left over by all the fixed-width and/or auto-width panels. Because of this, while you can specify any number of columns
  38. * with different percentages, the columnWidths must always add up to 1 (or 100%) when added together, otherwise your
  39. * layout may not render as expected. Example usage:&lt;/p&gt;
  40. * &lt;pre&gt;&lt;code&gt;
  41. // All columns are percentages -- they must add up to 1
  42. var p = new Ext.Panel({
  43. title: 'Column Layout - Percentage Only',
  44. layout:'column',
  45. items: [{
  46. title: 'Column 1',
  47. columnWidth: .25
  48. },{
  49. title: 'Column 2',
  50. columnWidth: .6
  51. },{
  52. title: 'Column 3',
  53. columnWidth: .15
  54. }]
  55. });
  56. // Mix of width and columnWidth -- all columnWidth values must add up
  57. // to 1. The first column will take up exactly 120px, and the last two
  58. // columns will fill the remaining container width.
  59. var p = new Ext.Panel({
  60. title: 'Column Layout - Mixed',
  61. layout:'column',
  62. items: [{
  63. title: 'Column 1',
  64. width: 120
  65. },{
  66. title: 'Column 2',
  67. columnWidth: .8
  68. },{
  69. title: 'Column 3',
  70. columnWidth: .2
  71. }]
  72. });
  73. &lt;/code&gt;&lt;/pre&gt;
  74. */
  75. Ext.layout.ColumnLayout = Ext.extend(Ext.layout.ContainerLayout, {
  76. <span id='Ext-layout-ColumnLayout-property-monitorResize'> // private
  77. </span> monitorResize:true,
  78. <span id='Ext-layout-ColumnLayout-property-type'> type: 'column',
  79. </span>
  80. <span id='Ext-layout-ColumnLayout-cfg-extraCls'> extraCls: 'x-column',
  81. </span>
  82. <span id='Ext-layout-ColumnLayout-property-scrollOffset'> scrollOffset : 0,
  83. </span>
  84. <span id='Ext-layout-ColumnLayout-property-targetCls'> // private
  85. </span>
  86. targetCls: 'x-column-layout-ct',
  87. <span id='Ext-layout-ColumnLayout-method-isValidParent'> isValidParent : function(c, target){
  88. </span> return this.innerCt &amp;&amp; c.getPositionEl().dom.parentNode == this.innerCt.dom;
  89. },
  90. <span id='Ext-layout-ColumnLayout-method-getLayoutTargetSize'> getLayoutTargetSize : function() {
  91. </span> var target = this.container.getLayoutTarget(), ret;
  92. if (target) {
  93. ret = target.getViewSize();
  94. // IE in strict mode will return a width of 0 on the 1st pass of getViewSize.
  95. // Use getStyleSize to verify the 0 width, the adjustment pass will then work properly
  96. // with getViewSize
  97. if (Ext.isIE9m &amp;&amp; Ext.isStrict &amp;&amp; ret.width == 0){
  98. ret = target.getStyleSize();
  99. }
  100. ret.width -= target.getPadding('lr');
  101. ret.height -= target.getPadding('tb');
  102. }
  103. return ret;
  104. },
  105. <span id='Ext-layout-ColumnLayout-method-renderAll'> renderAll : function(ct, target) {
  106. </span> if(!this.innerCt){
  107. // the innerCt prevents wrapping and shuffling while
  108. // the container is resizing
  109. this.innerCt = target.createChild({cls:'x-column-inner'});
  110. this.innerCt.createChild({cls:'x-clear'});
  111. }
  112. Ext.layout.ColumnLayout.superclass.renderAll.call(this, ct, this.innerCt);
  113. },
  114. <span id='Ext-layout-ColumnLayout-method-onLayout'> // private
  115. </span> onLayout : function(ct, target){
  116. var cs = ct.items.items,
  117. len = cs.length,
  118. c,
  119. i,
  120. m,
  121. margins = [];
  122. this.renderAll(ct, target);
  123. var size = this.getLayoutTargetSize();
  124. if (Ext.isIE9m &amp;&amp; (size.width &lt; 1 &amp;&amp; size.height &lt; 1)) { // display none?
  125. return;
  126. }
  127. var w = size.width - this.scrollOffset,
  128. h = size.height,
  129. pw = w;
  130. this.innerCt.setWidth(w);
  131. // some columns can be percentages while others are fixed
  132. // so we need to make 2 passes
  133. for(i = 0; i &lt; len; i++){
  134. c = cs[i];
  135. m = c.getPositionEl().getMargins('lr');
  136. margins[i] = m;
  137. if(!c.columnWidth){
  138. pw -= (c.getWidth() + m);
  139. }
  140. }
  141. pw = pw &lt; 0 ? 0 : pw;
  142. for(i = 0; i &lt; len; i++){
  143. c = cs[i];
  144. m = margins[i];
  145. if(c.columnWidth){
  146. c.setSize(Math.floor(c.columnWidth * pw) - m);
  147. }
  148. }
  149. // Browsers differ as to when they account for scrollbars. We need to re-measure to see if the scrollbar
  150. // spaces were accounted for properly. If not, re-layout.
  151. if (Ext.isIE9m) {
  152. if (i = target.getStyle('overflow') &amp;&amp; i != 'hidden' &amp;&amp; !this.adjustmentPass) {
  153. var ts = this.getLayoutTargetSize();
  154. if (ts.width != size.width){
  155. this.adjustmentPass = true;
  156. this.onLayout(ct, target);
  157. }
  158. }
  159. }
  160. delete this.adjustmentPass;
  161. }
  162. <span id='Ext-layout-ColumnLayout-property-activeItem'> /**
  163. </span> * @property activeItem
  164. * @hide
  165. */
  166. });
  167. Ext.Container.LAYOUTS['column'] = Ext.layout.ColumnLayout;
  168. </pre>
  169. </body>
  170. </html>