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.

215 lines
9.0 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-AccordionLayout'>/**
  19. </span> * @class Ext.layout.AccordionLayout
  20. * @extends Ext.layout.FitLayout
  21. * &lt;p&gt;This is a layout that manages multiple Panels in an expandable accordion style such that only
  22. * &lt;b&gt;one Panel can be expanded at any given time&lt;/b&gt;. Each Panel has built-in support for expanding and collapsing.&lt;/p&gt;
  23. * &lt;p&gt;Note: Only Ext.Panels &lt;b&gt;and all subclasses of Ext.Panel&lt;/b&gt; may be used in an accordion layout Container.&lt;/p&gt;
  24. * &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;
  25. * 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;
  26. * &lt;p&gt;Example usage:&lt;/p&gt;
  27. * &lt;pre&gt;&lt;code&gt;
  28. var accordion = new Ext.Panel({
  29. title: 'Accordion Layout',
  30. layout:'accordion',
  31. defaults: {
  32. // applied to each contained panel
  33. bodyStyle: 'padding:15px'
  34. },
  35. layoutConfig: {
  36. // layout-specific configs go here
  37. titleCollapse: false,
  38. animate: true,
  39. activeOnTop: true
  40. },
  41. items: [{
  42. title: 'Panel 1',
  43. html: '&amp;lt;p&amp;gt;Panel content!&amp;lt;/p&amp;gt;'
  44. },{
  45. title: 'Panel 2',
  46. html: '&amp;lt;p&amp;gt;Panel content!&amp;lt;/p&amp;gt;'
  47. },{
  48. title: 'Panel 3',
  49. html: '&amp;lt;p&amp;gt;Panel content!&amp;lt;/p&amp;gt;'
  50. }]
  51. });
  52. &lt;/code&gt;&lt;/pre&gt;
  53. */
  54. Ext.layout.AccordionLayout = Ext.extend(Ext.layout.FitLayout, {
  55. <span id='Ext-layout-AccordionLayout-cfg-fill'> /**
  56. </span> * @cfg {Boolean} fill
  57. * True to adjust the active item's height to fill the available space in the container, false to use the
  58. * item's current height, or auto height if not explicitly set (defaults to true).
  59. */
  60. fill : true,
  61. <span id='Ext-layout-AccordionLayout-cfg-autoWidth'> /**
  62. </span> * @cfg {Boolean} autoWidth
  63. * True to set each contained item's width to 'auto', false to use the item's current width (defaults to true).
  64. * Note that some components, in particular the {@link Ext.grid.GridPanel grid}, will not function properly within
  65. * layouts if they have auto width, so in such cases this config should be set to false.
  66. */
  67. autoWidth : true,
  68. <span id='Ext-layout-AccordionLayout-cfg-titleCollapse'> /**
  69. </span> * @cfg {Boolean} titleCollapse
  70. * True to allow expand/collapse of each contained panel by clicking anywhere on the title bar, false to allow
  71. * expand/collapse only when the toggle tool button is clicked (defaults to true). When set to false,
  72. * {@link #hideCollapseTool} should be false also.
  73. */
  74. titleCollapse : true,
  75. <span id='Ext-layout-AccordionLayout-cfg-hideCollapseTool'> /**
  76. </span> * @cfg {Boolean} hideCollapseTool
  77. * True to hide the contained panels' collapse/expand toggle buttons, false to display them (defaults to false).
  78. * When set to true, {@link #titleCollapse} should be true also.
  79. */
  80. hideCollapseTool : false,
  81. <span id='Ext-layout-AccordionLayout-cfg-collapseFirst'> /**
  82. </span> * @cfg {Boolean} collapseFirst
  83. * True to make sure the collapse/expand toggle button always renders first (to the left of) any other tools
  84. * in the contained panels' title bars, false to render it last (defaults to false).
  85. */
  86. collapseFirst : false,
  87. <span id='Ext-layout-AccordionLayout-cfg-animate'> /**
  88. </span> * @cfg {Boolean} animate
  89. * True to slide the contained panels open and closed during expand/collapse using animation, false to open and
  90. * close directly with no animation (defaults to false). Note: to defer to the specific config setting of each
  91. * contained panel for this property, set this to undefined at the layout level.
  92. */
  93. animate : false,
  94. <span id='Ext-layout-AccordionLayout-cfg-sequence'> /**
  95. </span> * @cfg {Boolean} sequence
  96. * &lt;b&gt;Experimental&lt;/b&gt;. If animate is set to true, this will result in each animation running in sequence.
  97. */
  98. sequence : false,
  99. <span id='Ext-layout-AccordionLayout-cfg-activeOnTop'> /**
  100. </span> * @cfg {Boolean} activeOnTop
  101. * True to swap the position of each panel as it is expanded so that it becomes the first item in the container,
  102. * false to keep the panels in the rendered order. &lt;b&gt;This is NOT compatible with &quot;animate:true&quot;&lt;/b&gt; (defaults to false).
  103. */
  104. activeOnTop : false,
  105. <span id='Ext-layout-AccordionLayout-property-type'> type: 'accordion',
  106. </span>
  107. <span id='Ext-layout-AccordionLayout-method-renderItem'> renderItem : function(c){
  108. </span> if(this.animate === false){
  109. c.animCollapse = false;
  110. }
  111. c.collapsible = true;
  112. if(this.autoWidth){
  113. c.autoWidth = true;
  114. }
  115. if(this.titleCollapse){
  116. c.titleCollapse = true;
  117. }
  118. if(this.hideCollapseTool){
  119. c.hideCollapseTool = true;
  120. }
  121. if(this.collapseFirst !== undefined){
  122. c.collapseFirst = this.collapseFirst;
  123. }
  124. if(!this.activeItem &amp;&amp; !c.collapsed){
  125. this.setActiveItem(c, true);
  126. }else if(this.activeItem &amp;&amp; this.activeItem != c){
  127. c.collapsed = true;
  128. }
  129. Ext.layout.AccordionLayout.superclass.renderItem.apply(this, arguments);
  130. c.header.addClass('x-accordion-hd');
  131. c.on('beforeexpand', this.beforeExpand, this);
  132. },
  133. <span id='Ext-layout-AccordionLayout-method-onRemove'> onRemove: function(c){
  134. </span> Ext.layout.AccordionLayout.superclass.onRemove.call(this, c);
  135. if(c.rendered){
  136. c.header.removeClass('x-accordion-hd');
  137. }
  138. c.un('beforeexpand', this.beforeExpand, this);
  139. },
  140. <span id='Ext-layout-AccordionLayout-method-beforeExpand'> // private
  141. </span> beforeExpand : function(p, anim){
  142. var ai = this.activeItem;
  143. if(ai){
  144. if(this.sequence){
  145. delete this.activeItem;
  146. if (!ai.collapsed){
  147. ai.collapse({callback:function(){
  148. p.expand(anim || true);
  149. }, scope: this});
  150. return false;
  151. }
  152. }else{
  153. ai.collapse(this.animate);
  154. }
  155. }
  156. this.setActive(p);
  157. if(this.activeOnTop){
  158. p.el.dom.parentNode.insertBefore(p.el.dom, p.el.dom.parentNode.firstChild);
  159. }
  160. // Items have been hidden an possibly rearranged, we need to get the container size again.
  161. this.layout();
  162. },
  163. <span id='Ext-layout-AccordionLayout-method-setItemSize'> // private
  164. </span> setItemSize : function(item, size){
  165. if(this.fill &amp;&amp; item){
  166. var hh = 0, i, ct = this.getRenderedItems(this.container), len = ct.length, p;
  167. // Add up all the header heights
  168. for (i = 0; i &lt; len; i++) {
  169. if((p = ct[i]) != item &amp;&amp; !p.hidden){
  170. hh += p.header.getHeight();
  171. }
  172. };
  173. // Subtract the header heights from the container size
  174. size.height -= hh;
  175. // Call setSize on the container to set the correct height. For Panels, deferedHeight
  176. // will simply store this size for when the expansion is done.
  177. item.setSize(size);
  178. }
  179. },
  180. <span id='Ext-layout-AccordionLayout-method-setActiveItem'> /**
  181. </span> * Sets the active (expanded) item in the layout.
  182. * @param {String/Number} item The string component id or numeric index of the item to activate
  183. */
  184. setActiveItem : function(item){
  185. this.setActive(item, true);
  186. },
  187. <span id='Ext-layout-AccordionLayout-method-setActive'> // private
  188. </span> setActive : function(item, expand){
  189. var ai = this.activeItem;
  190. item = this.container.getComponent(item);
  191. if(ai != item){
  192. if(item.rendered &amp;&amp; item.collapsed &amp;&amp; expand){
  193. item.expand();
  194. }else{
  195. if(ai){
  196. ai.fireEvent('deactivate', ai);
  197. }
  198. this.activeItem = item;
  199. item.fireEvent('activate', item);
  200. }
  201. }
  202. }
  203. });
  204. Ext.Container.LAYOUTS.accordion = Ext.layout.AccordionLayout;
  205. //backwards compat
  206. Ext.layout.Accordion = Ext.layout.AccordionLayout;</pre>
  207. </body>
  208. </html>