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.

453 lines
17 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-ToolbarLayout'>/**
  19. </span> * @class Ext.layout.ToolbarLayout
  20. * @extends Ext.layout.ContainerLayout
  21. * Layout manager used by Ext.Toolbar. This is highly specialised for use by Toolbars and would not
  22. * usually be used by any other class.
  23. */
  24. Ext.layout.ToolbarLayout = Ext.extend(Ext.layout.ContainerLayout, {
  25. <span id='Ext-layout-ToolbarLayout-property-monitorResize'> monitorResize : true,
  26. </span>
  27. <span id='Ext-layout-ToolbarLayout-property-type'> type: 'toolbar',
  28. </span>
  29. <span id='Ext-layout-ToolbarLayout-property-triggerWidth'> /**
  30. </span> * @property triggerWidth
  31. * @type Number
  32. * The width allocated for the menu trigger at the extreme right end of the Toolbar
  33. */
  34. triggerWidth: 18,
  35. <span id='Ext-layout-ToolbarLayout-property-noItemsMenuText'> /**
  36. </span> * @property noItemsMenuText
  37. * @type String
  38. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  39. */
  40. noItemsMenuText : '&lt;div class=&quot;x-toolbar-no-items&quot;&gt;(None)&lt;/div&gt;',
  41. <span id='Ext-layout-ToolbarLayout-property-lastOverflow'> /**
  42. </span> * @private
  43. * @property lastOverflow
  44. * @type Boolean
  45. * Used internally to record whether the last layout caused an overflow or not
  46. */
  47. lastOverflow: false,
  48. <span id='Ext-layout-ToolbarLayout-property-tableHTML'> /**
  49. </span> * @private
  50. * @property tableHTML
  51. * @type String
  52. * String used to build the HTML injected to support the Toolbar's layout. The align property is
  53. * injected into this string inside the td.x-toolbar-left element during onLayout.
  54. */
  55. tableHTML: [
  56. '&lt;table cellspacing=&quot;0&quot; class=&quot;x-toolbar-ct&quot;&gt;',
  57. '&lt;tbody&gt;',
  58. '&lt;tr&gt;',
  59. '&lt;td class=&quot;x-toolbar-left&quot; align=&quot;{0}&quot;&gt;',
  60. '&lt;table cellspacing=&quot;0&quot;&gt;',
  61. '&lt;tbody&gt;',
  62. '&lt;tr class=&quot;x-toolbar-left-row&quot;&gt;&lt;/tr&gt;',
  63. '&lt;/tbody&gt;',
  64. '&lt;/table&gt;',
  65. '&lt;/td&gt;',
  66. '&lt;td class=&quot;x-toolbar-right&quot; align=&quot;right&quot;&gt;',
  67. '&lt;table cellspacing=&quot;0&quot; class=&quot;x-toolbar-right-ct&quot;&gt;',
  68. '&lt;tbody&gt;',
  69. '&lt;tr&gt;',
  70. '&lt;td&gt;',
  71. '&lt;table cellspacing=&quot;0&quot;&gt;',
  72. '&lt;tbody&gt;',
  73. '&lt;tr class=&quot;x-toolbar-right-row&quot;&gt;&lt;/tr&gt;',
  74. '&lt;/tbody&gt;',
  75. '&lt;/table&gt;',
  76. '&lt;/td&gt;',
  77. '&lt;td&gt;',
  78. '&lt;table cellspacing=&quot;0&quot;&gt;',
  79. '&lt;tbody&gt;',
  80. '&lt;tr class=&quot;x-toolbar-extras-row&quot;&gt;&lt;/tr&gt;',
  81. '&lt;/tbody&gt;',
  82. '&lt;/table&gt;',
  83. '&lt;/td&gt;',
  84. '&lt;/tr&gt;',
  85. '&lt;/tbody&gt;',
  86. '&lt;/table&gt;',
  87. '&lt;/td&gt;',
  88. '&lt;/tr&gt;',
  89. '&lt;/tbody&gt;',
  90. '&lt;/table&gt;'
  91. ].join(&quot;&quot;),
  92. <span id='Ext-layout-ToolbarLayout-method-onLayout'> /**
  93. </span> * @private
  94. * Create the wrapping Toolbar HTML and render/move all the items into the correct places
  95. */
  96. onLayout : function(ct, target) {
  97. //render the Toolbar &lt;table&gt; HTML if it's not already present
  98. if (!this.leftTr) {
  99. var align = ct.buttonAlign == 'center' ? 'center' : 'left';
  100. target.addClass('x-toolbar-layout-ct');
  101. target.insertHtml('beforeEnd', String.format(this.tableHTML, align));
  102. this.leftTr = target.child('tr.x-toolbar-left-row', true);
  103. this.rightTr = target.child('tr.x-toolbar-right-row', true);
  104. this.extrasTr = target.child('tr.x-toolbar-extras-row', true);
  105. if (this.hiddenItem == undefined) {
  106. <span id='Ext-layout-ToolbarLayout-property-hiddenItems'> /**
  107. </span> * @property hiddenItems
  108. * @type Array
  109. * Holds all items that are currently hidden due to there not being enough space to render them
  110. * These items will appear on the expand menu.
  111. */
  112. this.hiddenItems = [];
  113. }
  114. }
  115. var side = ct.buttonAlign == 'right' ? this.rightTr : this.leftTr,
  116. items = ct.items.items,
  117. position = 0;
  118. //render each item if not already rendered, place it into the correct (left or right) target
  119. for (var i = 0, len = items.length, c; i &lt; len; i++, position++) {
  120. c = items[i];
  121. if (c.isFill) {
  122. side = this.rightTr;
  123. position = -1;
  124. } else if (!c.rendered) {
  125. c.render(this.insertCell(c, side, position));
  126. this.configureItem(c);
  127. } else {
  128. if (!c.xtbHidden &amp;&amp; !this.isValidParent(c, side.childNodes[position])) {
  129. var td = this.insertCell(c, side, position);
  130. td.appendChild(c.getPositionEl().dom);
  131. c.container = Ext.get(td);
  132. }
  133. }
  134. }
  135. //strip extra empty cells
  136. this.cleanup(this.leftTr);
  137. this.cleanup(this.rightTr);
  138. this.cleanup(this.extrasTr);
  139. this.fitToSize(target);
  140. },
  141. <span id='Ext-layout-ToolbarLayout-method-cleanup'> /**
  142. </span> * @private
  143. * Removes any empty nodes from the given element
  144. * @param {Ext.Element} el The element to clean up
  145. */
  146. cleanup : function(el) {
  147. var cn = el.childNodes, i, c;
  148. for (i = cn.length-1; i &gt;= 0 &amp;&amp; (c = cn[i]); i--) {
  149. if (!c.firstChild) {
  150. el.removeChild(c);
  151. }
  152. }
  153. },
  154. <span id='Ext-layout-ToolbarLayout-method-insertCell'> /**
  155. </span> * @private
  156. * Inserts the given Toolbar item into the given element
  157. * @param {Ext.Component} c The component to add
  158. * @param {Ext.Element} target The target to add the component to
  159. * @param {Number} position The position to add the component at
  160. */
  161. insertCell : function(c, target, position) {
  162. var td = document.createElement('td');
  163. td.className = 'x-toolbar-cell';
  164. target.insertBefore(td, target.childNodes[position] || null);
  165. return td;
  166. },
  167. <span id='Ext-layout-ToolbarLayout-method-hideItem'> /**
  168. </span> * @private
  169. * Hides an item because it will not fit in the available width. The item will be unhidden again
  170. * if the Toolbar is resized to be large enough to show it
  171. * @param {Ext.Component} item The item to hide
  172. */
  173. hideItem : function(item) {
  174. this.hiddenItems.push(item);
  175. item.xtbHidden = true;
  176. item.xtbWidth = item.getPositionEl().dom.parentNode.offsetWidth;
  177. item.hide();
  178. },
  179. <span id='Ext-layout-ToolbarLayout-method-unhideItem'> /**
  180. </span> * @private
  181. * Unhides an item that was previously hidden due to there not being enough space left on the Toolbar
  182. * @param {Ext.Component} item The item to show
  183. */
  184. unhideItem : function(item) {
  185. item.show();
  186. item.xtbHidden = false;
  187. this.hiddenItems.remove(item);
  188. },
  189. <span id='Ext-layout-ToolbarLayout-method-getItemWidth'> /**
  190. </span> * @private
  191. * Returns the width of the given toolbar item. If the item is currently hidden because there
  192. * is not enough room to render it, its previous width is returned
  193. * @param {Ext.Component} c The component to measure
  194. * @return {Number} The width of the item
  195. */
  196. getItemWidth : function(c) {
  197. return c.hidden ? (c.xtbWidth || 0) : c.getPositionEl().dom.parentNode.offsetWidth;
  198. },
  199. <span id='Ext-layout-ToolbarLayout-method-fitToSize'> /**
  200. </span> * @private
  201. * Called at the end of onLayout. At this point the Toolbar has already been resized, so we need
  202. * to fit the items into the available width. We add up the width required by all of the items in
  203. * the toolbar - if we don't have enough space we hide the extra items and render the expand menu
  204. * trigger.
  205. * @param {Ext.Element} target The Element the Toolbar is currently laid out within
  206. */
  207. fitToSize : function(target) {
  208. if (this.container.enableOverflow === false) {
  209. return;
  210. }
  211. var width = target.dom.clientWidth,
  212. tableWidth = target.dom.firstChild.offsetWidth,
  213. clipWidth = width - this.triggerWidth,
  214. lastWidth = this.lastWidth || 0,
  215. hiddenItems = this.hiddenItems,
  216. hasHiddens = hiddenItems.length != 0,
  217. isLarger = width &gt;= lastWidth;
  218. this.lastWidth = width;
  219. if (tableWidth &gt; width || (hasHiddens &amp;&amp; isLarger)) {
  220. var items = this.container.items.items,
  221. len = items.length,
  222. loopWidth = 0,
  223. item;
  224. for (var i = 0; i &lt; len; i++) {
  225. item = items[i];
  226. if (!item.isFill) {
  227. loopWidth += this.getItemWidth(item);
  228. if (loopWidth &gt; clipWidth) {
  229. if (!(item.hidden || item.xtbHidden)) {
  230. this.hideItem(item);
  231. }
  232. } else if (item.xtbHidden) {
  233. this.unhideItem(item);
  234. }
  235. }
  236. }
  237. }
  238. //test for number of hidden items again here because they may have changed above
  239. hasHiddens = hiddenItems.length != 0;
  240. if (hasHiddens) {
  241. this.initMore();
  242. if (!this.lastOverflow) {
  243. this.container.fireEvent('overflowchange', this.container, true);
  244. this.lastOverflow = true;
  245. }
  246. } else if (this.more) {
  247. this.clearMenu();
  248. this.more.destroy();
  249. delete this.more;
  250. if (this.lastOverflow) {
  251. this.container.fireEvent('overflowchange', this.container, false);
  252. this.lastOverflow = false;
  253. }
  254. }
  255. },
  256. <span id='Ext-layout-ToolbarLayout-method-createMenuConfig'> /**
  257. </span> * @private
  258. * Returns a menu config for a given component. This config is used to create a menu item
  259. * to be added to the expander menu
  260. * @param {Ext.Component} component The component to create the config for
  261. * @param {Boolean} hideOnClick Passed through to the menu item
  262. */
  263. createMenuConfig : function(component, hideOnClick){
  264. var config = Ext.apply({}, component.initialConfig),
  265. group = component.toggleGroup;
  266. Ext.copyTo(config, component, [
  267. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  268. ]);
  269. Ext.apply(config, {
  270. text : component.overflowText || component.text,
  271. hideOnClick: hideOnClick
  272. });
  273. if (group || component.enableToggle) {
  274. Ext.apply(config, {
  275. group : group,
  276. checked: component.pressed,
  277. listeners: {
  278. checkchange: function(item, checked){
  279. component.toggle(checked);
  280. }
  281. }
  282. });
  283. }
  284. delete config.ownerCt;
  285. delete config.xtype;
  286. delete config.id;
  287. return config;
  288. },
  289. <span id='Ext-layout-ToolbarLayout-method-addComponentToMenu'> /**
  290. </span> * @private
  291. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  292. * @param {Ext.menu.Menu} menu The menu to add to
  293. * @param {Ext.Component} component The component to add
  294. */
  295. addComponentToMenu : function(menu, component) {
  296. if (component instanceof Ext.Toolbar.Separator) {
  297. menu.add('-');
  298. } else if (Ext.isFunction(component.isXType)) {
  299. if (component.isXType('splitbutton')) {
  300. menu.add(this.createMenuConfig(component, true));
  301. } else if (component.isXType('button')) {
  302. menu.add(this.createMenuConfig(component, !component.menu));
  303. } else if (component.isXType('buttongroup')) {
  304. component.items.each(function(item){
  305. this.addComponentToMenu(menu, item);
  306. }, this);
  307. }
  308. }
  309. },
  310. <span id='Ext-layout-ToolbarLayout-method-clearMenu'> /**
  311. </span> * @private
  312. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  313. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  314. */
  315. clearMenu : function(){
  316. var menu = this.moreMenu;
  317. if (menu &amp;&amp; menu.items) {
  318. menu.items.each(function(item){
  319. delete item.menu;
  320. });
  321. }
  322. },
  323. <span id='Ext-layout-ToolbarLayout-method-beforeMoreShow'> /**
  324. </span> * @private
  325. * Called before the expand menu is shown, this rebuilds the menu since it was last shown because
  326. * it is possible that the items hidden due to space limitations on the Toolbar have changed since.
  327. * @param {Ext.menu.Menu} m The menu
  328. */
  329. beforeMoreShow : function(menu) {
  330. var items = this.container.items.items,
  331. len = items.length,
  332. item,
  333. prev;
  334. var needsSep = function(group, item){
  335. return group.isXType('buttongroup') &amp;&amp; !(item instanceof Ext.Toolbar.Separator);
  336. };
  337. this.clearMenu();
  338. menu.removeAll();
  339. for (var i = 0; i &lt; len; i++) {
  340. item = items[i];
  341. if (item.xtbHidden) {
  342. if (prev &amp;&amp; (needsSep(item, prev) || needsSep(prev, item))) {
  343. menu.add('-');
  344. }
  345. this.addComponentToMenu(menu, item);
  346. prev = item;
  347. }
  348. }
  349. // put something so the menu isn't empty if no compatible items found
  350. if (menu.items.length &lt; 1) {
  351. menu.add(this.noItemsMenuText);
  352. }
  353. },
  354. <span id='Ext-layout-ToolbarLayout-method-initMore'> /**
  355. </span> * @private
  356. * Creates the expand trigger and menu, adding them to the &lt;tr&gt; at the extreme right of the
  357. * Toolbar table
  358. */
  359. initMore : function(){
  360. if (!this.more) {
  361. <span id='Ext-layout-ToolbarLayout-property-moreMenu'> /**
  362. </span> * @private
  363. * @property moreMenu
  364. * @type Ext.menu.Menu
  365. * The expand menu - holds items for every Toolbar item that cannot be shown
  366. * because the Toolbar is currently not wide enough.
  367. */
  368. this.moreMenu = new Ext.menu.Menu({
  369. ownerCt : this.container,
  370. listeners: {
  371. beforeshow: this.beforeMoreShow,
  372. scope: this
  373. }
  374. });
  375. <span id='Ext-layout-ToolbarLayout-property-more'> /**
  376. </span> * @private
  377. * @property more
  378. * @type Ext.Button
  379. * The expand button which triggers the overflow menu to be shown
  380. */
  381. this.more = new Ext.Button({
  382. iconCls: 'x-toolbar-more-icon',
  383. cls : 'x-toolbar-more',
  384. menu : this.moreMenu,
  385. ownerCt: this.container
  386. });
  387. var td = this.insertCell(this.more, this.extrasTr, 100);
  388. this.more.render(td);
  389. }
  390. },
  391. <span id='Ext-layout-ToolbarLayout-method-destroy'> destroy : function(){
  392. </span> Ext.destroy(this.more, this.moreMenu);
  393. delete this.leftTr;
  394. delete this.rightTr;
  395. delete this.extrasTr;
  396. Ext.layout.ToolbarLayout.superclass.destroy.call(this);
  397. }
  398. });
  399. Ext.Container.LAYOUTS.toolbar = Ext.layout.ToolbarLayout;
  400. </pre>
  401. </body>
  402. </html>