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.

322 lines
13 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-ContainerLayout'>/**
  19. </span> * @class Ext.layout.ContainerLayout
  20. * &lt;p&gt;This class is intended to be extended or created via the &lt;tt&gt;&lt;b&gt;{@link Ext.Container#layout layout}&lt;/b&gt;&lt;/tt&gt;
  21. * configuration property. See &lt;tt&gt;&lt;b&gt;{@link Ext.Container#layout}&lt;/b&gt;&lt;/tt&gt; for additional details.&lt;/p&gt;
  22. */
  23. Ext.layout.ContainerLayout = Ext.extend(Object, {
  24. <span id='Ext-layout-ContainerLayout-cfg-extraCls'> /**
  25. </span> * @cfg {String} extraCls
  26. * &lt;p&gt;An optional extra CSS class that will be added to the container. This can be useful for adding
  27. * customized styles to the container or any of its children using standard CSS rules. See
  28. * {@link Ext.Component}.{@link Ext.Component#ctCls ctCls} also.&lt;/p&gt;
  29. * &lt;p&gt;&lt;b&gt;Note&lt;/b&gt;: &lt;tt&gt;extraCls&lt;/tt&gt; defaults to &lt;tt&gt;''&lt;/tt&gt; except for the following classes
  30. * which assign a value by default:
  31. * &lt;div class=&quot;mdetail-params&quot;&gt;&lt;ul&gt;
  32. * &lt;li&gt;{@link Ext.layout.AbsoluteLayout Absolute Layout} : &lt;tt&gt;'x-abs-layout-item'&lt;/tt&gt;&lt;/li&gt;
  33. * &lt;li&gt;{@link Ext.layout.Box Box Layout} : &lt;tt&gt;'x-box-item'&lt;/tt&gt;&lt;/li&gt;
  34. * &lt;li&gt;{@link Ext.layout.ColumnLayout Column Layout} : &lt;tt&gt;'x-column'&lt;/tt&gt;&lt;/li&gt;
  35. * &lt;/ul&gt;&lt;/div&gt;
  36. * To configure the above Classes with an extra CSS class append to the default. For example,
  37. * for ColumnLayout:&lt;pre&gt;&lt;code&gt;
  38. * extraCls: 'x-column custom-class'
  39. * &lt;/code&gt;&lt;/pre&gt;
  40. * &lt;/p&gt;
  41. */
  42. <span id='Ext-layout-ContainerLayout-cfg-renderHidden'> /**
  43. </span> * @cfg {Boolean} renderHidden
  44. * True to hide each contained item on render (defaults to false).
  45. */
  46. <span id='Ext-layout-ContainerLayout-property-activeItem'> /**
  47. </span> * A reference to the {@link Ext.Component} that is active. For example, &lt;pre&gt;&lt;code&gt;
  48. * if(myPanel.layout.activeItem.id == 'item-1') { ... }
  49. * &lt;/code&gt;&lt;/pre&gt;
  50. * &lt;tt&gt;activeItem&lt;/tt&gt; only applies to layout styles that can display items one at a time
  51. * (like {@link Ext.layout.AccordionLayout}, {@link Ext.layout.CardLayout}
  52. * and {@link Ext.layout.FitLayout}). Read-only. Related to {@link Ext.Container#activeItem}.
  53. * @type {Ext.Component}
  54. * @property activeItem
  55. */
  56. <span id='Ext-layout-ContainerLayout-property-monitorResize'> // private
  57. </span> monitorResize:false,
  58. <span id='Ext-layout-ContainerLayout-property-activeItem'> // private
  59. </span> activeItem : null,
  60. <span id='Ext-layout-ContainerLayout-method-constructor'> constructor : function(config){
  61. </span> this.id = Ext.id(null, 'ext-layout-');
  62. Ext.apply(this, config);
  63. },
  64. <span id='Ext-layout-ContainerLayout-property-type'> type: 'container',
  65. </span>
  66. <span id='Ext-layout-ContainerLayout-method-IEMeasureHack'> /* Workaround for how IE measures autoWidth elements. It prefers bottom-up measurements
  67. </span> whereas other browser prefer top-down. We will hide all target child elements before we measure and
  68. put them back to get an accurate measurement.
  69. */
  70. IEMeasureHack : function(target, viewFlag) {
  71. var tChildren = target.dom.childNodes, tLen = tChildren.length, c, d = [], e, i, ret;
  72. for (i = 0 ; i &lt; tLen ; i++) {
  73. c = tChildren[i];
  74. e = Ext.get(c);
  75. if (e) {
  76. d[i] = e.getStyle('display');
  77. e.setStyle({display: 'none'});
  78. }
  79. }
  80. ret = target ? target.getViewSize(viewFlag) : {};
  81. for (i = 0 ; i &lt; tLen ; i++) {
  82. c = tChildren[i];
  83. e = Ext.get(c);
  84. if (e) {
  85. e.setStyle({display: d[i]});
  86. }
  87. }
  88. return ret;
  89. },
  90. <span id='Ext-layout-ContainerLayout-property-getLayoutTargetSize'> // Placeholder for the derived layouts
  91. </span> getLayoutTargetSize : Ext.EmptyFn,
  92. <span id='Ext-layout-ContainerLayout-method-layout'> // private
  93. </span> layout : function(){
  94. var ct = this.container, target = ct.getLayoutTarget();
  95. if(!(this.hasLayout || Ext.isEmpty(this.targetCls))){
  96. target.addClass(this.targetCls);
  97. }
  98. this.onLayout(ct, target);
  99. ct.fireEvent('afterlayout', ct, this);
  100. },
  101. <span id='Ext-layout-ContainerLayout-method-onLayout'> // private
  102. </span> onLayout : function(ct, target){
  103. this.renderAll(ct, target);
  104. },
  105. <span id='Ext-layout-ContainerLayout-method-isValidParent'> // private
  106. </span> isValidParent : function(c, target){
  107. return target &amp;&amp; c.getPositionEl().dom.parentNode == (target.dom || target);
  108. },
  109. <span id='Ext-layout-ContainerLayout-method-renderAll'> // private
  110. </span> renderAll : function(ct, target){
  111. var items = ct.items.items, i, c, len = items.length;
  112. for(i = 0; i &lt; len; i++) {
  113. c = items[i];
  114. if(c &amp;&amp; (!c.rendered || !this.isValidParent(c, target))){
  115. this.renderItem(c, i, target);
  116. }
  117. }
  118. },
  119. <span id='Ext-layout-ContainerLayout-method-renderItem'> /**
  120. </span> * @private
  121. * Renders the given Component into the target Element. If the Component is already rendered,
  122. * it is moved to the provided target instead.
  123. * @param {Ext.Component} c The Component to render
  124. * @param {Number} position The position within the target to render the item to
  125. * @param {Ext.Element} target The target Element
  126. */
  127. renderItem : function(c, position, target){
  128. if (c) {
  129. if (!c.rendered) {
  130. c.render(target, position);
  131. this.configureItem(c);
  132. } else if (!this.isValidParent(c, target)) {
  133. if (Ext.isNumber(position)) {
  134. position = target.dom.childNodes[position];
  135. }
  136. target.dom.insertBefore(c.getPositionEl().dom, position || null);
  137. c.container = target;
  138. this.configureItem(c);
  139. }
  140. }
  141. },
  142. <span id='Ext-layout-ContainerLayout-method-getRenderedItems'> // private.
  143. </span> // Get all rendered items to lay out.
  144. getRenderedItems: function(ct){
  145. var t = ct.getLayoutTarget(), cti = ct.items.items, len = cti.length, i, c, items = [];
  146. for (i = 0; i &lt; len; i++) {
  147. if((c = cti[i]).rendered &amp;&amp; this.isValidParent(c, t) &amp;&amp; c.shouldLayout !== false){
  148. items.push(c);
  149. }
  150. };
  151. return items;
  152. },
  153. <span id='Ext-layout-ContainerLayout-method-configureItem'> /**
  154. </span> * @private
  155. * Applies extraCls and hides the item if renderHidden is true
  156. */
  157. configureItem: function(c){
  158. if (this.extraCls) {
  159. var t = c.getPositionEl ? c.getPositionEl() : c;
  160. t.addClass(this.extraCls);
  161. }
  162. // If we are forcing a layout, do so *before* we hide so elements have height/width
  163. if (c.doLayout &amp;&amp; this.forceLayout) {
  164. c.doLayout();
  165. }
  166. if (this.renderHidden &amp;&amp; c != this.activeItem) {
  167. c.hide();
  168. }
  169. },
  170. <span id='Ext-layout-ContainerLayout-method-onRemove'> onRemove: function(c){
  171. </span> if(this.activeItem == c){
  172. delete this.activeItem;
  173. }
  174. if(c.rendered &amp;&amp; this.extraCls){
  175. var t = c.getPositionEl ? c.getPositionEl() : c;
  176. t.removeClass(this.extraCls);
  177. }
  178. },
  179. <span id='Ext-layout-ContainerLayout-method-afterRemove'> afterRemove: function(c){
  180. </span> if(c.removeRestore){
  181. c.removeMode = 'container';
  182. delete c.removeRestore;
  183. }
  184. },
  185. <span id='Ext-layout-ContainerLayout-method-onResize'> // private
  186. </span> onResize: function(){
  187. var ct = this.container,
  188. b;
  189. if(ct.collapsed){
  190. return;
  191. }
  192. if(b = ct.bufferResize &amp;&amp; ct.shouldBufferLayout()){
  193. if(!this.resizeTask){
  194. this.resizeTask = new Ext.util.DelayedTask(this.runLayout, this);
  195. this.resizeBuffer = Ext.isNumber(b) ? b : 50;
  196. }
  197. ct.layoutPending = true;
  198. this.resizeTask.delay(this.resizeBuffer);
  199. }else{
  200. this.runLayout();
  201. }
  202. },
  203. <span id='Ext-layout-ContainerLayout-method-runLayout'> runLayout: function(){
  204. </span> var ct = this.container;
  205. this.layout();
  206. ct.onLayout();
  207. delete ct.layoutPending;
  208. },
  209. <span id='Ext-layout-ContainerLayout-method-setContainer'> // private
  210. </span> setContainer : function(ct){
  211. /*
  212. * This monitorResize flag will be renamed soon as to avoid confusion
  213. * with the Container version which hooks onWindowResize to doLayout
  214. *
  215. * monitorResize flag in this context attaches the resize event between
  216. * a container and it's layout
  217. */
  218. if(this.monitorResize &amp;&amp; ct != this.container){
  219. var old = this.container;
  220. if(old){
  221. old.un(old.resizeEvent, this.onResize, this);
  222. }
  223. if(ct){
  224. ct.on(ct.resizeEvent, this.onResize, this);
  225. }
  226. }
  227. this.container = ct;
  228. },
  229. <span id='Ext-layout-ContainerLayout-method-parseMargins'> /**
  230. </span> * Parses a number or string representing margin sizes into an object. Supports CSS-style margin declarations
  231. * (e.g. 10, &quot;10&quot;, &quot;10 10&quot;, &quot;10 10 10&quot; and &quot;10 10 10 10&quot; are all valid options and would return the same result)
  232. * @param {Number|String} v The encoded margins
  233. * @return {Object} An object with margin sizes for top, right, bottom and left
  234. */
  235. parseMargins : function(v){
  236. if (Ext.isNumber(v)) {
  237. v = v.toString();
  238. }
  239. var ms = v.split(' '),
  240. len = ms.length;
  241. if (len == 1) {
  242. ms[1] = ms[2] = ms[3] = ms[0];
  243. } else if(len == 2) {
  244. ms[2] = ms[0];
  245. ms[3] = ms[1];
  246. } else if(len == 3) {
  247. ms[3] = ms[1];
  248. }
  249. return {
  250. top :parseInt(ms[0], 10) || 0,
  251. right :parseInt(ms[1], 10) || 0,
  252. bottom:parseInt(ms[2], 10) || 0,
  253. left :parseInt(ms[3], 10) || 0
  254. };
  255. },
  256. <span id='Ext-layout-ContainerLayout-property-fieldTpl'> /**
  257. </span> * The {@link Ext.Template Ext.Template} used by Field rendering layout classes (such as
  258. * {@link Ext.layout.FormLayout}) to create the DOM structure of a fully wrapped,
  259. * labeled and styled form Field. A default Template is supplied, but this may be
  260. * overriden to create custom field structures. The template processes values returned from
  261. * {@link Ext.layout.FormLayout#getTemplateArgs}.
  262. * @property fieldTpl
  263. * @type Ext.Template
  264. */
  265. fieldTpl: (function() {
  266. var t = new Ext.Template(
  267. '&lt;div class=&quot;x-form-item {itemCls}&quot; tabIndex=&quot;-1&quot;&gt;',
  268. '&lt;label for=&quot;{id}&quot; style=&quot;{labelStyle}&quot; class=&quot;x-form-item-label&quot;&gt;{label}{labelSeparator}&lt;/label&gt;',
  269. '&lt;div class=&quot;x-form-element&quot; id=&quot;x-form-el-{id}&quot; style=&quot;{elementStyle}&quot;&gt;',
  270. '&lt;/div&gt;&lt;div class=&quot;{clearCls}&quot;&gt;&lt;/div&gt;',
  271. '&lt;/div&gt;'
  272. );
  273. t.disableFormats = true;
  274. return t.compile();
  275. })(),
  276. <span id='Ext-layout-ContainerLayout-method-destroy'> /*
  277. </span> * Destroys this layout. This is a template method that is empty by default, but should be implemented
  278. * by subclasses that require explicit destruction to purge event handlers or remove DOM nodes.
  279. * @protected
  280. */
  281. destroy : function(){
  282. // Stop any buffered layout tasks
  283. if(this.resizeTask &amp;&amp; this.resizeTask.cancel){
  284. this.resizeTask.cancel();
  285. }
  286. if(this.container) {
  287. this.container.un(this.container.resizeEvent, this.onResize, this);
  288. }
  289. if(!Ext.isEmpty(this.targetCls)){
  290. var target = this.container.getLayoutTarget();
  291. if(target){
  292. target.removeClass(this.targetCls);
  293. }
  294. }
  295. }
  296. });</pre>
  297. </body>
  298. </html>