DockingContainer.html 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287
  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-container-DockingContainer'>/**
  19. </span> *
  20. */
  21. Ext.define('Ext.container.DockingContainer', {
  22. /* Begin Definitions */
  23. requires: ['Ext.util.MixedCollection', 'Ext.Element' ],
  24. /* End Definitions */
  25. isDockingContainer: true,
  26. <span id='Ext-container-DockingContainer-cfg-defaultDockWeights'> /**
  27. </span> * @cfg {Object} defaultDockWeights
  28. * This object holds the default weights applied to dockedItems that have no weight. These start with a
  29. * weight of 1, to allow negative weights to insert before top items and are odd numbers
  30. * so that even weights can be used to get between different dock orders.
  31. *
  32. * To make default docking order match border layout, do this:
  33. *
  34. * Ext.panel.AbstractPanel.prototype.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };
  35. *
  36. * Changing these defaults as above or individually on this object will effect all Panels.
  37. * To change the defaults on a single panel, you should replace the entire object:
  38. *
  39. * initComponent: function () {
  40. * // NOTE: Don't change members of defaultDockWeights since the object is shared.
  41. * this.defaultDockWeights = { top: 1, bottom: 3, left: 5, right: 7 };
  42. *
  43. * this.callParent();
  44. * }
  45. *
  46. * To change only one of the default values, you do this:
  47. *
  48. * initComponent: function () {
  49. * // NOTE: Don't change members of defaultDockWeights since the object is shared.
  50. * this.defaultDockWeights = Ext.applyIf({ top: 10 }, this.defaultDockWeights);
  51. *
  52. * this.callParent();
  53. * }
  54. */
  55. defaultDockWeights: {
  56. top: { render: 1, visual: 1 },
  57. left: { render: 3, visual: 5 },
  58. right: { render: 5, visual: 7 },
  59. bottom: { render: 7, visual: 3 }
  60. },
  61. // @private
  62. // Values to decide which side of the body element docked items must go
  63. // This overides any weight. A left/top will *always* sort before a right/bottom
  64. // regardless of any weight value. Weights sort at either side of the &quot;body&quot; dividing point.
  65. dockOrder: {
  66. top: -1,
  67. left: -1,
  68. right: 1,
  69. bottom: 1
  70. },
  71. <span id='Ext-container-DockingContainer-method-addDocked'> /**
  72. </span> * Adds docked item(s) to the container.
  73. *
  74. * @param {Object/Object[]} component The Component or array of components to add. The components
  75. * must include a 'dock' parameter on each component to indicate where it should be docked
  76. * ('top', 'right', 'bottom', 'left').
  77. * @param {Number} [pos] The index at which the Component will be added
  78. * @return {Ext.Component[]} The added components.
  79. */
  80. addDocked : function(items, pos) {
  81. var me = this,
  82. i = 0,
  83. item, length;
  84. items = me.prepareItems(items);
  85. length = items.length;
  86. for (; i &lt; length; i++) {
  87. item = items[i];
  88. item.dock = item.dock || 'top';
  89. if (pos !== undefined) {
  90. me.dockedItems.insert(pos + i, item);
  91. } else {
  92. me.dockedItems.add(item);
  93. }
  94. if (item.onAdded !== Ext.emptyFn) {
  95. item.onAdded(me, i);
  96. }
  97. if (me.onDockedAdd !== Ext.emptyFn) {
  98. me.onDockedAdd(item);
  99. }
  100. }
  101. if (me.rendered &amp;&amp; !me.suspendLayout) {
  102. me.updateLayout();
  103. }
  104. return items;
  105. },
  106. destroyDockedItems: function(){
  107. var dockedItems = this.dockedItems,
  108. c;
  109. if (dockedItems) {
  110. while ((c = dockedItems.first())) {
  111. this.removeDocked(c, true);
  112. }
  113. }
  114. },
  115. doRenderDockedItems: function (out, renderData, after) {
  116. // Careful! This method is bolted on to the frameTpl and renderTpl so all we get for
  117. // context is the renderData! The &quot;this&quot; pointer is either the frameTpl or the
  118. // renderTpl instance!
  119. // Due to framing, we will be called in two different ways: in the frameTpl or in
  120. // the renderTpl. The frameTpl version enters via doRenderFramingDockedItems which
  121. // sets &quot;$skipDockedItems&quot; on the renderTpl's renderData.
  122. //
  123. var me = renderData.$comp,
  124. layout = me.componentLayout,
  125. items,
  126. tree;
  127. if (layout.getDockedItems &amp;&amp; !renderData.$skipDockedItems) {
  128. items = layout.getDockedItems('render', !after);
  129. tree = items &amp;&amp; layout.getItemsRenderTree(items);
  130. if (tree) {
  131. Ext.DomHelper.generateMarkup(tree, out);
  132. }
  133. }
  134. },
  135. <span id='Ext-container-DockingContainer-method-getDockedComponent'> /**
  136. </span> * Finds a docked component by id, itemId or position. Also see {@link #getDockedItems}
  137. * @param {String/Number} comp The id, itemId or position of the docked component (see {@link Ext.panel.AbstractPanel#getComponent getComponent} for details)
  138. * @return {Ext.Component} The docked component (if found)
  139. */
  140. getDockedComponent: function(comp) {
  141. if (Ext.isObject(comp)) {
  142. comp = comp.getItemId();
  143. }
  144. return this.dockedItems.get(comp);
  145. },
  146. <span id='Ext-container-DockingContainer-method-getDockedItems'> /**
  147. </span> * Retrieves an array of all currently docked Components.
  148. *
  149. * For example to find a toolbar that has been docked at top:
  150. *
  151. * panel.getDockedItems('toolbar[dock=&quot;top&quot;]');
  152. *
  153. * @param {String} selector A {@link Ext.ComponentQuery ComponentQuery} selector string to filter the returned items.
  154. * @param {Boolean} beforeBody An optional flag to limit the set of items to only those
  155. * before the body (true) or after the body (false). All components are returned by
  156. * default.
  157. * @return {Ext.Component[]} The array of docked components meeting the specified criteria.
  158. */
  159. getDockedItems : function(selector, beforeBody) {
  160. var dockedItems = this.getComponentLayout().getDockedItems('render', beforeBody);
  161. if (selector &amp;&amp; dockedItems.length) {
  162. dockedItems = Ext.ComponentQuery.query(selector, dockedItems);
  163. }
  164. return dockedItems;
  165. },
  166. getDockingRefItems: function(deep, containerItems) {
  167. // deep fetches the docked items and their descendants using '*' and then '* *'
  168. var selector = deep &amp;&amp; '*,* *',
  169. // start with only the top/left docked items (and maybe their children)
  170. dockedItems = this.getDockedItems(selector, true),
  171. items;
  172. // push container items (and maybe their children) after top/left docked items:
  173. dockedItems.push.apply(dockedItems, containerItems);
  174. // push right/bottom docked items (and maybe their children) after container items:
  175. items = this.getDockedItems(selector, false);
  176. dockedItems.push.apply(dockedItems, items);
  177. return dockedItems;
  178. },
  179. initDockingItems: function() {
  180. var me = this,
  181. items = me.dockedItems;
  182. me.dockedItems = new Ext.util.AbstractMixedCollection(false, me.getComponentId);
  183. if (items) {
  184. me.addDocked(items);
  185. }
  186. },
  187. <span id='Ext-container-DockingContainer-method-insertDocked'> /**
  188. </span> * Inserts docked item(s) to the panel at the indicated position.
  189. * @param {Number} pos The index at which the Component will be inserted
  190. * @param {Object/Object[]} component. The Component or array of components to add. The components
  191. * must include a 'dock' paramater on each component to indicate where it should be docked ('top', 'right',
  192. * 'bottom', 'left').
  193. */
  194. insertDocked : function(pos, items) {
  195. this.addDocked(items, pos);
  196. },
  197. // Placeholder empty functions
  198. <span id='Ext-container-DockingContainer-method-onDockedAdd'> /**
  199. </span> * Invoked after a docked item is added to the Panel.
  200. * @param {Ext.Component} component
  201. * @template
  202. * @protected
  203. */
  204. onDockedAdd : Ext.emptyFn,
  205. <span id='Ext-container-DockingContainer-method-onDockedRemove'> /**
  206. </span> * Invoked after a docked item is removed from the Panel.
  207. * @param {Ext.Component} component
  208. * @template
  209. * @protected
  210. */
  211. onDockedRemove : Ext.emptyFn,
  212. <span id='Ext-container-DockingContainer-method-removeDocked'> /**
  213. </span> * Removes the docked item from the panel.
  214. * @param {Ext.Component} item. The Component to remove.
  215. * @param {Boolean} autoDestroy (optional) Destroy the component after removal.
  216. */
  217. removeDocked : function(item, autoDestroy) {
  218. var me = this,
  219. layout,
  220. hasLayout;
  221. if (!me.dockedItems.contains(item)) {
  222. return item;
  223. }
  224. layout = me.componentLayout;
  225. hasLayout = layout &amp;&amp; me.rendered;
  226. if (hasLayout) {
  227. layout.onRemove(item);
  228. }
  229. me.dockedItems.remove(item);
  230. item.onRemoved();
  231. me.onDockedRemove(item);
  232. if (autoDestroy === true || (autoDestroy !== false &amp;&amp; me.autoDestroy)) {
  233. item.destroy();
  234. } else if (hasLayout) {
  235. // not destroying, make any layout related removals
  236. layout.afterRemove(item);
  237. }
  238. if (!me.destroying &amp;&amp; !me.suspendLayout) {
  239. me.updateLayout();
  240. }
  241. return item;
  242. },
  243. setupDockingRenderTpl: function (renderTpl) {
  244. renderTpl.renderDockedItems = this.doRenderDockedItems;
  245. }
  246. });
  247. </pre>
  248. </body>
  249. </html>