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.

364 lines
12 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-boxOverflow-Menu'>/**
  19. </span> * @class Ext.layout.boxOverflow.Menu
  20. * @extends Ext.layout.boxOverflow.None
  21. * Description
  22. */
  23. Ext.layout.boxOverflow.Menu = Ext.extend(Ext.layout.boxOverflow.None, {
  24. <span id='Ext-layout-boxOverflow-Menu-property-afterCls'> /**
  25. </span> * @cfg afterCls
  26. * @type String
  27. * CSS class added to the afterCt element. This is the element that holds any special items such as scrollers,
  28. * which must always be present at the rightmost edge of the Container
  29. */
  30. afterCls: 'x-strip-right',
  31. <span id='Ext-layout-boxOverflow-Menu-property-noItemsMenuText'> /**
  32. </span> * @property noItemsMenuText
  33. * @type String
  34. * HTML fragment to render into the toolbar overflow menu if there are no items to display
  35. */
  36. noItemsMenuText : '&lt;div class=&quot;x-toolbar-no-items&quot;&gt;(None)&lt;/div&gt;',
  37. <span id='Ext-layout-boxOverflow-Menu-method-constructor'> constructor: function(layout) {
  38. </span> Ext.layout.boxOverflow.Menu.superclass.constructor.apply(this, arguments);
  39. <span id='Ext-layout-boxOverflow-Menu-property-menuItems'> /**
  40. </span> * @property menuItems
  41. * @type Array
  42. * Array of all items that are currently hidden and should go into the dropdown menu
  43. */
  44. this.menuItems = [];
  45. },
  46. <span id='Ext-layout-boxOverflow-Menu-method-createInnerElements'> /**
  47. </span> * @private
  48. * Creates the beforeCt, innerCt and afterCt elements if they have not already been created
  49. * @param {Ext.Container} container The Container attached to this Layout instance
  50. * @param {Ext.Element} target The target Element
  51. */
  52. createInnerElements: function() {
  53. if (!this.afterCt) {
  54. this.afterCt = this.layout.innerCt.insertSibling({cls: this.afterCls}, 'before');
  55. }
  56. },
  57. <span id='Ext-layout-boxOverflow-Menu-method-clearOverflow'> /**
  58. </span> * @private
  59. */
  60. clearOverflow: function(calculations, targetSize) {
  61. var newWidth = targetSize.width + (this.afterCt ? this.afterCt.getWidth() : 0),
  62. items = this.menuItems;
  63. this.hideTrigger();
  64. for (var index = 0, length = items.length; index &lt; length; index++) {
  65. items.pop().component.show();
  66. }
  67. return {
  68. targetSize: {
  69. height: targetSize.height,
  70. width : newWidth
  71. }
  72. };
  73. },
  74. <span id='Ext-layout-boxOverflow-Menu-method-showTrigger'> /**
  75. </span> * @private
  76. */
  77. showTrigger: function() {
  78. this.createMenu();
  79. this.menuTrigger.show();
  80. },
  81. <span id='Ext-layout-boxOverflow-Menu-method-hideTrigger'> /**
  82. </span> * @private
  83. */
  84. hideTrigger: function() {
  85. if (this.menuTrigger != undefined) {
  86. this.menuTrigger.hide();
  87. }
  88. },
  89. <span id='Ext-layout-boxOverflow-Menu-method-beforeMenuShow'> /**
  90. </span> * @private
  91. * Called before the overflow menu is shown. This constructs the menu's items, caching them for as long as it can.
  92. */
  93. beforeMenuShow: function(menu) {
  94. var items = this.menuItems,
  95. len = items.length,
  96. item,
  97. prev;
  98. var needsSep = function(group, item){
  99. return group.isXType('buttongroup') &amp;&amp; !(item instanceof Ext.Toolbar.Separator);
  100. };
  101. this.clearMenu();
  102. menu.removeAll();
  103. for (var i = 0; i &lt; len; i++) {
  104. item = items[i].component;
  105. if (prev &amp;&amp; (needsSep(item, prev) || needsSep(prev, item))) {
  106. menu.add('-');
  107. }
  108. this.addComponentToMenu(menu, item);
  109. prev = item;
  110. }
  111. // put something so the menu isn't empty if no compatible items found
  112. if (menu.items.length &lt; 1) {
  113. menu.add(this.noItemsMenuText);
  114. }
  115. },
  116. <span id='Ext-layout-boxOverflow-Menu-method-createMenuConfig'> /**
  117. </span> * @private
  118. * Returns a menu config for a given component. This config is used to create a menu item
  119. * to be added to the expander menu
  120. * @param {Ext.Component} component The component to create the config for
  121. * @param {Boolean} hideOnClick Passed through to the menu item
  122. */
  123. createMenuConfig : function(component, hideOnClick){
  124. var config = Ext.apply({}, component.initialConfig),
  125. group = component.toggleGroup;
  126. Ext.copyTo(config, component, [
  127. 'iconCls', 'icon', 'itemId', 'disabled', 'handler', 'scope', 'menu'
  128. ]);
  129. Ext.apply(config, {
  130. text : component.overflowText || component.text,
  131. hideOnClick: hideOnClick
  132. });
  133. if (group || component.enableToggle) {
  134. Ext.apply(config, {
  135. group : group,
  136. checked: component.pressed,
  137. listeners: {
  138. checkchange: function(item, checked){
  139. component.toggle(checked);
  140. }
  141. }
  142. });
  143. }
  144. delete config.ownerCt;
  145. delete config.xtype;
  146. delete config.id;
  147. return config;
  148. },
  149. <span id='Ext-layout-boxOverflow-Menu-method-addComponentToMenu'> /**
  150. </span> * @private
  151. * Adds the given Toolbar item to the given menu. Buttons inside a buttongroup are added individually.
  152. * @param {Ext.menu.Menu} menu The menu to add to
  153. * @param {Ext.Component} component The component to add
  154. */
  155. addComponentToMenu : function(menu, component) {
  156. if (component instanceof Ext.Toolbar.Separator) {
  157. menu.add('-');
  158. } else if (Ext.isFunction(component.isXType)) {
  159. if (component.isXType('splitbutton')) {
  160. menu.add(this.createMenuConfig(component, true));
  161. } else if (component.isXType('button')) {
  162. menu.add(this.createMenuConfig(component, !component.menu));
  163. } else if (component.isXType('buttongroup')) {
  164. component.items.each(function(item){
  165. this.addComponentToMenu(menu, item);
  166. }, this);
  167. }
  168. }
  169. },
  170. <span id='Ext-layout-boxOverflow-Menu-method-clearMenu'> /**
  171. </span> * @private
  172. * Deletes the sub-menu of each item in the expander menu. Submenus are created for items such as
  173. * splitbuttons and buttongroups, where the Toolbar item cannot be represented by a single menu item
  174. */
  175. clearMenu : function(){
  176. var menu = this.moreMenu;
  177. if (menu &amp;&amp; menu.items) {
  178. menu.items.each(function(item){
  179. delete item.menu;
  180. });
  181. }
  182. },
  183. <span id='Ext-layout-boxOverflow-Menu-method-createMenu'> /**
  184. </span> * @private
  185. * Creates the overflow trigger and menu used when enableOverflow is set to true and the items
  186. * in the layout are too wide to fit in the space available
  187. */
  188. createMenu: function() {
  189. if (!this.menuTrigger) {
  190. this.createInnerElements();
  191. <span id='Ext-layout-boxOverflow-Menu-property-menu'> /**
  192. </span> * @private
  193. * @property menu
  194. * @type Ext.menu.Menu
  195. * The expand menu - holds items for every item that cannot be shown
  196. * because the container is currently not large enough.
  197. */
  198. this.menu = new Ext.menu.Menu({
  199. ownerCt : this.layout.container,
  200. listeners: {
  201. scope: this,
  202. beforeshow: this.beforeMenuShow
  203. }
  204. });
  205. <span id='Ext-layout-boxOverflow-Menu-property-menuTrigger'> /**
  206. </span> * @private
  207. * @property menuTrigger
  208. * @type Ext.Button
  209. * The expand button which triggers the overflow menu to be shown
  210. */
  211. this.menuTrigger = new Ext.Button({
  212. iconCls : 'x-toolbar-more-icon',
  213. cls : 'x-toolbar-more',
  214. menu : this.menu,
  215. renderTo: this.afterCt
  216. });
  217. }
  218. },
  219. <span id='Ext-layout-boxOverflow-Menu-method-destroy'> /**
  220. </span> * @private
  221. */
  222. destroy: function() {
  223. Ext.destroy(this.menu, this.menuTrigger);
  224. }
  225. });
  226. Ext.layout.boxOverflow.menu = Ext.layout.boxOverflow.Menu;
  227. <span id='Ext-layout-boxOverflow-HorizontalMenu'>/**
  228. </span> * @class Ext.layout.boxOverflow.HorizontalMenu
  229. * @extends Ext.layout.boxOverflow.Menu
  230. * Description
  231. */
  232. Ext.layout.boxOverflow.HorizontalMenu = Ext.extend(Ext.layout.boxOverflow.Menu, {
  233. <span id='Ext-layout-boxOverflow-HorizontalMenu-method-constructor'> constructor: function() {
  234. </span> Ext.layout.boxOverflow.HorizontalMenu.superclass.constructor.apply(this, arguments);
  235. var me = this,
  236. layout = me.layout,
  237. origFunction = layout.calculateChildBoxes;
  238. layout.calculateChildBoxes = function(visibleItems, targetSize) {
  239. var calcs = origFunction.apply(layout, arguments),
  240. meta = calcs.meta,
  241. items = me.menuItems;
  242. //calculate the width of the items currently hidden solely because there is not enough space
  243. //to display them
  244. var hiddenWidth = 0;
  245. for (var index = 0, length = items.length; index &lt; length; index++) {
  246. hiddenWidth += items[index].width;
  247. }
  248. meta.minimumWidth += hiddenWidth;
  249. meta.tooNarrow = meta.minimumWidth &gt; targetSize.width;
  250. return calcs;
  251. };
  252. },
  253. <span id='Ext-layout-boxOverflow-HorizontalMenu-method-handleOverflow'> handleOverflow: function(calculations, targetSize) {
  254. </span> this.showTrigger();
  255. var newWidth = targetSize.width - this.afterCt.getWidth(),
  256. boxes = calculations.boxes,
  257. usedWidth = 0,
  258. recalculate = false;
  259. //calculate the width of all visible items and any spare width
  260. for (var index = 0, length = boxes.length; index &lt; length; index++) {
  261. usedWidth += boxes[index].width;
  262. }
  263. var spareWidth = newWidth - usedWidth,
  264. showCount = 0;
  265. //see if we can re-show any of the hidden components
  266. for (var index = 0, length = this.menuItems.length; index &lt; length; index++) {
  267. var hidden = this.menuItems[index],
  268. comp = hidden.component,
  269. width = hidden.width;
  270. if (width &lt; spareWidth) {
  271. comp.show();
  272. spareWidth -= width;
  273. showCount ++;
  274. recalculate = true;
  275. } else {
  276. break;
  277. }
  278. }
  279. if (recalculate) {
  280. this.menuItems = this.menuItems.slice(showCount);
  281. } else {
  282. for (var i = boxes.length - 1; i &gt;= 0; i--) {
  283. var item = boxes[i].component,
  284. right = boxes[i].left + boxes[i].width;
  285. if (right &gt;= newWidth) {
  286. this.menuItems.unshift({
  287. component: item,
  288. width : boxes[i].width
  289. });
  290. item.hide();
  291. } else {
  292. break;
  293. }
  294. }
  295. }
  296. if (this.menuItems.length == 0) {
  297. this.hideTrigger();
  298. }
  299. return {
  300. targetSize: {
  301. height: targetSize.height,
  302. width : newWidth
  303. },
  304. recalculate: recalculate
  305. };
  306. }
  307. });
  308. Ext.layout.boxOverflow.menu.hbox = Ext.layout.boxOverflow.HorizontalMenu;</pre>
  309. </body>
  310. </html>