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.

1741 lines
56 KiB

2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
2 years ago
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*
  2. This file is part of Ext JS 3.4
  3. Copyright (c) 2011-2013 Sencha Inc
  4. Contact: http://www.sencha.com/contact
  5. GNU General Public License Usage
  6. This file may be used under the terms of the GNU General Public License version 3.0 as
  7. published by the Free Software Foundation and appearing in the file LICENSE included in the
  8. packaging of this file.
  9. Please review the following information to ensure the GNU General Public License version 3.0
  10. requirements will be met: http://www.gnu.org/copyleft/gpl.html.
  11. If you are unsure which license is appropriate for your use, please contact the sales department
  12. at http://www.sencha.com/contact.
  13. Build date: 2013-04-03 15:07:25
  14. */
  15. /**
  16. * @class Ext.menu.Menu
  17. * @extends Ext.Container
  18. * <p>A menu object. This is the container to which you may add menu items. Menu can also serve as a base class
  19. * when you want a specialized menu based off of another component (like {@link Ext.menu.DateMenu} for example).</p>
  20. * <p>Menus may contain either {@link Ext.menu.Item menu items}, or general {@link Ext.Component Component}s.</p>
  21. * <p>To make a contained general {@link Ext.Component Component} line up with other {@link Ext.menu.Item menu items}
  22. * specify <tt>iconCls: 'no-icon'</tt>. This reserves a space for an icon, and indents the Component in line
  23. * with the other menu items. See {@link Ext.form.ComboBox}.{@link Ext.form.ComboBox#getListParent getListParent}
  24. * for an example.</p>
  25. * <p>By default, Menus are absolutely positioned, floating Components. By configuring a Menu with
  26. * <b><tt>{@link #floating}:false</tt></b>, a Menu may be used as child of a Container.</p>
  27. *
  28. * @xtype menu
  29. */
  30. Ext.menu.Menu = Ext.extend(Ext.Container, {
  31. /**
  32. * @cfg {Object} defaults
  33. * A config object that will be applied to all items added to this container either via the {@link #items}
  34. * config or via the {@link #add} method. The defaults config can contain any number of
  35. * name/value property pairs to be added to each item, and should be valid for the types of items
  36. * being added to the menu.
  37. */
  38. /**
  39. * @cfg {Mixed} items
  40. * An array of items to be added to this menu. Menus may contain either {@link Ext.menu.Item menu items},
  41. * or general {@link Ext.Component Component}s.
  42. */
  43. /**
  44. * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
  45. */
  46. minWidth : 120,
  47. /**
  48. * @cfg {Boolean/String} shadow True or 'sides' for the default effect, 'frame' for 4-way shadow, and 'drop'
  49. * for bottom-right shadow (defaults to 'sides')
  50. */
  51. shadow : 'sides',
  52. /**
  53. * @cfg {String} subMenuAlign The {@link Ext.Element#alignTo} anchor position value to use for submenus of
  54. * this menu (defaults to 'tl-tr?')
  55. */
  56. subMenuAlign : 'tl-tr?',
  57. /**
  58. * @cfg {String} defaultAlign The default {@link Ext.Element#alignTo} anchor position value for this menu
  59. * relative to its element of origin (defaults to 'tl-bl?')
  60. */
  61. defaultAlign : 'tl-bl?',
  62. /**
  63. * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
  64. */
  65. allowOtherMenus : false,
  66. /**
  67. * @cfg {Boolean} ignoreParentClicks True to ignore clicks on any item in this menu that is a parent item (displays
  68. * a submenu) so that the submenu is not dismissed when clicking the parent item (defaults to false).
  69. */
  70. ignoreParentClicks : false,
  71. /**
  72. * @cfg {Boolean} enableScrolling True to allow the menu container to have scroller controls if the menu is too long (defaults to true).
  73. */
  74. enableScrolling : true,
  75. /**
  76. * @cfg {Number} maxHeight The maximum height of the menu. Only applies when enableScrolling is set to True (defaults to null).
  77. */
  78. maxHeight : null,
  79. /**
  80. * @cfg {Number} scrollIncrement The amount to scroll the menu. Only applies when enableScrolling is set to True (defaults to 24).
  81. */
  82. scrollIncrement : 24,
  83. /**
  84. * @cfg {Boolean} showSeparator True to show the icon separator. (defaults to true).
  85. */
  86. showSeparator : true,
  87. /**
  88. * @cfg {Array} defaultOffsets An array specifying the [x, y] offset in pixels by which to
  89. * change the default Menu popup position after aligning according to the {@link #defaultAlign}
  90. * configuration. Defaults to <tt>[0, 0]</tt>.
  91. */
  92. defaultOffsets : [0, 0],
  93. /**
  94. * @cfg {Boolean} plain
  95. * True to remove the incised line down the left side of the menu. Defaults to <tt>false</tt>.
  96. */
  97. plain : false,
  98. /**
  99. * @cfg {Boolean} floating
  100. * <p>By default, a Menu configured as <b><code>floating:true</code></b>
  101. * will be rendered as an {@link Ext.Layer} (an absolutely positioned,
  102. * floating Component with zindex=15000).
  103. * If configured as <b><code>floating:false</code></b>, the Menu may be
  104. * used as child item of another Container instead of a free-floating
  105. * {@link Ext.Layer Layer}.
  106. */
  107. floating : true,
  108. /**
  109. * @cfg {Number} zIndex
  110. * zIndex to use when the menu is floating.
  111. */
  112. zIndex: 15000,
  113. // private
  114. hidden : true,
  115. /**
  116. * @cfg {String/Object} layout
  117. * This class assigns a default layout (<code>layout:'<b>menu</b>'</code>).
  118. * Developers <i>may</i> override this configuration option if another layout is required.
  119. * See {@link Ext.Container#layout} for additional information.
  120. */
  121. layout : 'menu',
  122. hideMode : 'offsets', // Important for laying out Components
  123. scrollerHeight : 8,
  124. autoLayout : true, // Provided for backwards compat
  125. defaultType : 'menuitem',
  126. bufferResize : false,
  127. initComponent : function(){
  128. if(Ext.isArray(this.initialConfig)){
  129. Ext.apply(this, {items:this.initialConfig});
  130. }
  131. this.addEvents(
  132. /**
  133. * @event click
  134. * Fires when this menu is clicked (or when the enter key is pressed while it is active)
  135. * @param {Ext.menu.Menu} this
  136. * @param {Ext.menu.Item} menuItem The menu item that was clicked
  137. * @param {Ext.EventObject} e
  138. */
  139. 'click',
  140. /**
  141. * @event mouseover
  142. * Fires when the mouse is hovering over this menu
  143. * @param {Ext.menu.Menu} this
  144. * @param {Ext.EventObject} e
  145. * @param {Ext.menu.Item} menuItem The menu item that was clicked
  146. */
  147. 'mouseover',
  148. /**
  149. * @event mouseout
  150. * Fires when the mouse exits this menu
  151. * @param {Ext.menu.Menu} this
  152. * @param {Ext.EventObject} e
  153. * @param {Ext.menu.Item} menuItem The menu item that was clicked
  154. */
  155. 'mouseout',
  156. /**
  157. * @event itemclick
  158. * Fires when a menu item contained in this menu is clicked
  159. * @param {Ext.menu.BaseItem} baseItem The BaseItem that was clicked
  160. * @param {Ext.EventObject} e
  161. */
  162. 'itemclick'
  163. );
  164. Ext.menu.MenuMgr.register(this);
  165. if(this.floating){
  166. Ext.EventManager.onWindowResize(this.hide, this);
  167. }else{
  168. if(this.initialConfig.hidden !== false){
  169. this.hidden = false;
  170. }
  171. this.internalDefaults = {hideOnClick: false};
  172. }
  173. Ext.menu.Menu.superclass.initComponent.call(this);
  174. if(this.autoLayout){
  175. var fn = this.doLayout.createDelegate(this, []);
  176. this.on({
  177. add: fn,
  178. remove: fn
  179. });
  180. }
  181. },
  182. //private
  183. getLayoutTarget : function() {
  184. return this.ul;
  185. },
  186. // private
  187. onRender : function(ct, position){
  188. if(!ct){
  189. ct = Ext.getBody();
  190. }
  191. var dh = {
  192. id: this.getId(),
  193. cls: 'x-menu ' + ((this.floating) ? 'x-menu-floating x-layer ' : '') + (this.cls || '') + (this.plain ? ' x-menu-plain' : '') + (this.showSeparator ? '' : ' x-menu-nosep'),
  194. style: this.style,
  195. cn: [
  196. {tag: 'a', cls: 'x-menu-focus', href: '#', onclick: 'return false;', tabIndex: '-1'},
  197. {tag: 'ul', cls: 'x-menu-list'}
  198. ]
  199. };
  200. if(this.floating){
  201. this.el = new Ext.Layer({
  202. shadow: this.shadow,
  203. dh: dh,
  204. constrain: false,
  205. parentEl: ct,
  206. zindex: this.zIndex
  207. });
  208. }else{
  209. this.el = ct.createChild(dh);
  210. }
  211. Ext.menu.Menu.superclass.onRender.call(this, ct, position);
  212. if(!this.keyNav){
  213. this.keyNav = new Ext.menu.MenuNav(this);
  214. }
  215. // generic focus element
  216. this.focusEl = this.el.child('a.x-menu-focus');
  217. this.ul = this.el.child('ul.x-menu-list');
  218. this.mon(this.ul, {
  219. scope: this,
  220. click: this.onClick,
  221. mouseover: this.onMouseOver,
  222. mouseout: this.onMouseOut
  223. });
  224. if(this.enableScrolling){
  225. this.mon(this.el, {
  226. scope: this,
  227. delegate: '.x-menu-scroller',
  228. click: this.onScroll,
  229. mouseover: this.deactivateActive
  230. });
  231. }
  232. },
  233. // private
  234. findTargetItem : function(e){
  235. var t = e.getTarget('.x-menu-list-item', this.ul, true);
  236. if(t && t.menuItemId){
  237. return this.items.get(t.menuItemId);
  238. }
  239. },
  240. // private
  241. onClick : function(e){
  242. var t = this.findTargetItem(e);
  243. if(t){
  244. if(t.isFormField){
  245. this.setActiveItem(t);
  246. }else if(t instanceof Ext.menu.BaseItem){
  247. if(t.menu && this.ignoreParentClicks){
  248. t.expandMenu();
  249. e.preventDefault();
  250. }else if(t.onClick){
  251. t.onClick(e);
  252. this.fireEvent('click', this, t, e);
  253. }
  254. }
  255. }
  256. },
  257. // private
  258. setActiveItem : function(item, autoExpand){
  259. if(item != this.activeItem){
  260. this.deactivateActive();
  261. if((this.activeItem = item).isFormField){
  262. item.focus();
  263. }else{
  264. item.activate(autoExpand);
  265. }
  266. }else if(autoExpand){
  267. item.expandMenu();
  268. }
  269. },
  270. deactivateActive : function(){
  271. var a = this.activeItem;
  272. if(a){
  273. if(a.isFormField){
  274. //Fields cannot deactivate, but Combos must collapse
  275. if(a.collapse){
  276. a.collapse();
  277. }
  278. }else{
  279. a.deactivate();
  280. }
  281. delete this.activeItem;
  282. }
  283. },
  284. // private
  285. tryActivate : function(start, step){
  286. var items = this.items;
  287. for(var i = start, len = items.length; i >= 0 && i < len; i+= step){
  288. var item = items.get(i);
  289. if(item.isVisible() && !item.disabled && (item.canActivate || item.isFormField)){
  290. this.setActiveItem(item, false);
  291. return item;
  292. }
  293. }
  294. return false;
  295. },
  296. // private
  297. onMouseOver : function(e){
  298. var t = this.findTargetItem(e);
  299. if(t){
  300. if(t.canActivate && !t.disabled){
  301. this.setActiveItem(t, true);
  302. }
  303. }
  304. this.over = true;
  305. this.fireEvent('mouseover', this, e, t);
  306. },
  307. // private
  308. onMouseOut : function(e){
  309. var t = this.findTargetItem(e);
  310. if(t){
  311. if(t == this.activeItem && t.shouldDeactivate && t.shouldDeactivate(e)){
  312. this.activeItem.deactivate();
  313. delete this.activeItem;
  314. }
  315. }
  316. this.over = false;
  317. this.fireEvent('mouseout', this, e, t);
  318. },
  319. // private
  320. onScroll : function(e, t){
  321. if(e){
  322. e.stopEvent();
  323. }
  324. var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top');
  325. ul.scrollTop += this.scrollIncrement * (top ? -1 : 1);
  326. if(top ? ul.scrollTop <= 0 : ul.scrollTop + this.activeMax >= ul.scrollHeight){
  327. this.onScrollerOut(null, t);
  328. }
  329. },
  330. // private
  331. onScrollerIn : function(e, t){
  332. var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top');
  333. if(top ? ul.scrollTop > 0 : ul.scrollTop + this.activeMax < ul.scrollHeight){
  334. Ext.fly(t).addClass(['x-menu-item-active', 'x-menu-scroller-active']);
  335. }
  336. },
  337. // private
  338. onScrollerOut : function(e, t){
  339. Ext.fly(t).removeClass(['x-menu-item-active', 'x-menu-scroller-active']);
  340. },
  341. /**
  342. * If <code>{@link #floating}=true</code>, shows this menu relative to
  343. * another element using {@link #showat}, otherwise uses {@link Ext.Component#show}.
  344. * @param {Mixed} element The element to align to
  345. * @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to
  346. * the element (defaults to this.defaultAlign)
  347. * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
  348. */
  349. show : function(el, pos, parentMenu){
  350. if(this.floating){
  351. this.parentMenu = parentMenu;
  352. if(!this.el){
  353. this.render();
  354. this.doLayout(false, true);
  355. }
  356. this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign, this.defaultOffsets), parentMenu);
  357. }else{
  358. Ext.menu.Menu.superclass.show.call(this);
  359. }
  360. },
  361. /**
  362. * Displays this menu at a specific xy position and fires the 'show' event if a
  363. * handler for the 'beforeshow' event does not return false cancelling the operation.
  364. * @param {Array} xyPosition Contains X & Y [x, y] values for the position at which to show the menu (coordinates are page-based)
  365. * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
  366. */
  367. showAt : function(xy, parentMenu){
  368. if(this.fireEvent('beforeshow', this) !== false){
  369. this.parentMenu = parentMenu;
  370. if(!this.el){
  371. this.render();
  372. }
  373. if(this.enableScrolling){
  374. // set the position so we can figure out the constrain value.
  375. this.el.setXY(xy);
  376. //constrain the value, keep the y coordinate the same
  377. xy[1] = this.constrainScroll(xy[1]);
  378. xy = [this.el.adjustForConstraints(xy)[0], xy[1]];
  379. }else{
  380. //constrain to the viewport.
  381. xy = this.el.adjustForConstraints(xy);
  382. }
  383. this.el.setXY(xy);
  384. this.el.show();
  385. Ext.menu.Menu.superclass.onShow.call(this);
  386. if(Ext.isIE9m){
  387. // internal event, used so we don't couple the layout to the menu
  388. this.fireEvent('autosize', this);
  389. if(!Ext.isIE8){
  390. this.el.repaint();
  391. }
  392. }
  393. this.hidden = false;
  394. this.focus();
  395. this.fireEvent('show', this);
  396. }
  397. },
  398. constrainScroll : function(y){
  399. var max, full = this.ul.setHeight('auto').getHeight(),
  400. returnY = y, normalY, parentEl, scrollTop, viewHeight;
  401. if(this.floating){
  402. parentEl = Ext.fly(this.el.dom.parentNode);
  403. scrollTop = parentEl.getScroll().top;
  404. viewHeight = parentEl.getViewSize().height;
  405. //Normalize y by the scroll position for the parent element. Need to move it into the coordinate space
  406. //of the view.
  407. normalY = y - scrollTop;
  408. max = this.maxHeight ? this.maxHeight : viewHeight - normalY;
  409. if(full > viewHeight) {
  410. max = viewHeight;
  411. //Set returnY equal to (0,0) in view space by reducing y by the value of normalY
  412. returnY = y - normalY;
  413. } else if(max < full) {
  414. returnY = y - (full - max);
  415. max = full;
  416. }
  417. }else{
  418. max = this.getHeight();
  419. }
  420. // Always respect maxHeight
  421. if (this.maxHeight){
  422. max = Math.min(this.maxHeight, max);
  423. }
  424. if(full > max && max > 0){
  425. this.activeMax = max - this.scrollerHeight * 2 - this.el.getFrameWidth('tb') - Ext.num(this.el.shadowOffset, 0);
  426. this.ul.setHeight(this.activeMax);
  427. this.createScrollers();
  428. this.el.select('.x-menu-scroller').setDisplayed('');
  429. }else{
  430. this.ul.setHeight(full);
  431. this.el.select('.x-menu-scroller').setDisplayed('none');
  432. }
  433. this.ul.dom.scrollTop = 0;
  434. return returnY;
  435. },
  436. createScrollers : function(){
  437. if(!this.scroller){
  438. this.scroller = {
  439. pos: 0,
  440. top: this.el.insertFirst({
  441. tag: 'div',
  442. cls: 'x-menu-scroller x-menu-scroller-top',
  443. html: '&#160;'
  444. }),
  445. bottom: this.el.createChild({
  446. tag: 'div',
  447. cls: 'x-menu-scroller x-menu-scroller-bottom',
  448. html: '&#160;'
  449. })
  450. };
  451. this.scroller.top.hover(this.onScrollerIn, this.onScrollerOut, this);
  452. this.scroller.topRepeater = new Ext.util.ClickRepeater(this.scroller.top, {
  453. listeners: {
  454. click: this.onScroll.createDelegate(this, [null, this.scroller.top], false)
  455. }
  456. });
  457. this.scroller.bottom.hover(this.onScrollerIn, this.onScrollerOut, this);
  458. this.scroller.bottomRepeater = new Ext.util.ClickRepeater(this.scroller.bottom, {
  459. listeners: {
  460. click: this.onScroll.createDelegate(this, [null, this.scroller.bottom], false)
  461. }
  462. });
  463. }
  464. },
  465. onLayout : function(){
  466. if(this.isVisible()){
  467. if(this.enableScrolling){
  468. this.constrainScroll(this.el.getTop());
  469. }
  470. if(this.floating){
  471. this.el.sync();
  472. }
  473. }
  474. },
  475. focus : function(){
  476. if(!this.hidden){
  477. this.doFocus.defer(50, this);
  478. }
  479. },
  480. doFocus : function(){
  481. if(!this.hidden){
  482. this.focusEl.focus();
  483. }
  484. },
  485. /**
  486. * Hides this menu and optionally all parent menus
  487. * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
  488. */
  489. hide : function(deep){
  490. if (!this.isDestroyed) {
  491. this.deepHide = deep;
  492. Ext.menu.Menu.superclass.hide.call(this);
  493. delete this.deepHide;
  494. }
  495. },
  496. // private
  497. onHide : function(){
  498. Ext.menu.Menu.superclass.onHide.call(this);
  499. this.deactivateActive();
  500. if(this.el && this.floating){
  501. this.el.hide();
  502. }
  503. var pm = this.parentMenu;
  504. if(this.deepHide === true && pm){
  505. if(pm.floating){
  506. pm.hide(true);
  507. }else{
  508. pm.deactivateActive();
  509. }
  510. }
  511. },
  512. // private
  513. lookupComponent : function(c){
  514. if(Ext.isString(c)){
  515. c = (c == 'separator' || c == '-') ? new Ext.menu.Separator() : new Ext.menu.TextItem(c);
  516. this.applyDefaults(c);
  517. }else{
  518. if(Ext.isObject(c)){
  519. c = this.getMenuItem(c);
  520. }else if(c.tagName || c.el){ // element. Wrap it.
  521. c = new Ext.BoxComponent({
  522. el: c
  523. });
  524. }
  525. }
  526. return c;
  527. },
  528. applyDefaults : function(c) {
  529. if (!Ext.isString(c)) {
  530. c = Ext.menu.Menu.superclass.applyDefaults.call(this, c);
  531. var d = this.internalDefaults;
  532. if(d){
  533. if(c.events){
  534. Ext.applyIf(c.initialConfig, d);
  535. Ext.apply(c, d);
  536. }else{
  537. Ext.applyIf(c, d);
  538. }
  539. }
  540. }
  541. return c;
  542. },
  543. // private
  544. getMenuItem : function(config) {
  545. config.ownerCt = this;
  546. if (!config.isXType) {
  547. if (!config.xtype && Ext.isBoolean(config.checked)) {
  548. return new Ext.menu.CheckItem(config);
  549. }
  550. return Ext.create(config, this.defaultType);
  551. }
  552. return config;
  553. },
  554. /**
  555. * Adds a separator bar to the menu
  556. * @return {Ext.menu.Item} The menu item that was added
  557. */
  558. addSeparator : function() {
  559. return this.add(new Ext.menu.Separator());
  560. },
  561. /**
  562. * Adds an {@link Ext.Element} object to the menu
  563. * @param {Mixed} el The element or DOM node to add, or its id
  564. * @return {Ext.menu.Item} The menu item that was added
  565. */
  566. addElement : function(el) {
  567. return this.add(new Ext.menu.BaseItem({
  568. el: el
  569. }));
  570. },
  571. /**
  572. * Adds an existing object based on {@link Ext.menu.BaseItem} to the menu
  573. * @param {Ext.menu.Item} item The menu item to add
  574. * @return {Ext.menu.Item} The menu item that was added
  575. */
  576. addItem : function(item) {
  577. return this.add(item);
  578. },
  579. /**
  580. * Creates a new {@link Ext.menu.Item} based an the supplied config object and adds it to the menu
  581. * @param {Object} config A MenuItem config object
  582. * @return {Ext.menu.Item} The menu item that was added
  583. */
  584. addMenuItem : function(config) {
  585. return this.add(this.getMenuItem(config));
  586. },
  587. /**
  588. * Creates a new {@link Ext.menu.TextItem} with the supplied text and adds it to the menu
  589. * @param {String} text The text to display in the menu item
  590. * @return {Ext.menu.Item} The menu item that was added
  591. */
  592. addText : function(text){
  593. return this.add(new Ext.menu.TextItem(text));
  594. },
  595. //private
  596. onDestroy : function(){
  597. Ext.EventManager.removeResizeListener(this.hide, this);
  598. var pm = this.parentMenu;
  599. if(pm && pm.activeChild == this){
  600. delete pm.activeChild;
  601. }
  602. delete this.parentMenu;
  603. Ext.menu.Menu.superclass.onDestroy.call(this);
  604. Ext.menu.MenuMgr.unregister(this);
  605. if(this.keyNav) {
  606. this.keyNav.disable();
  607. }
  608. var s = this.scroller;
  609. if(s){
  610. Ext.destroy(s.topRepeater, s.bottomRepeater, s.top, s.bottom);
  611. }
  612. Ext.destroy(
  613. this.el,
  614. this.focusEl,
  615. this.ul
  616. );
  617. }
  618. });
  619. Ext.reg('menu', Ext.menu.Menu);
  620. // MenuNav is a private utility class used internally by the Menu
  621. Ext.menu.MenuNav = Ext.extend(Ext.KeyNav, function(){
  622. function up(e, m){
  623. if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
  624. m.tryActivate(m.items.length-1, -1);
  625. }
  626. }
  627. function down(e, m){
  628. if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
  629. m.tryActivate(0, 1);
  630. }
  631. }
  632. return {
  633. constructor : function(menu){
  634. Ext.menu.MenuNav.superclass.constructor.call(this, menu.el);
  635. this.scope = this.menu = menu;
  636. },
  637. doRelay : function(e, h){
  638. var k = e.getKey();
  639. // Keystrokes within a form Field (e.g.: down in a Combo) do not navigate. Allow only TAB
  640. if (this.menu.activeItem && this.menu.activeItem.isFormField && k != e.TAB) {
  641. return false;
  642. }
  643. if(!this.menu.activeItem && e.isNavKeyPress() && k != e.SPACE && k != e.RETURN){
  644. this.menu.tryActivate(0, 1);
  645. return false;
  646. }
  647. return h.call(this.scope || this, e, this.menu);
  648. },
  649. tab: function(e, m) {
  650. e.stopEvent();
  651. if (e.shiftKey) {
  652. up(e, m);
  653. } else {
  654. down(e, m);
  655. }
  656. },
  657. up : up,
  658. down : down,
  659. right : function(e, m){
  660. if(m.activeItem){
  661. m.activeItem.expandMenu(true);
  662. }
  663. },
  664. left : function(e, m){
  665. m.hide();
  666. if(m.parentMenu && m.parentMenu.activeItem){
  667. m.parentMenu.activeItem.activate();
  668. }
  669. },
  670. enter : function(e, m){
  671. if(m.activeItem){
  672. e.stopPropagation();
  673. m.activeItem.onClick(e);
  674. m.fireEvent('click', this, m.activeItem);
  675. return true;
  676. }
  677. }
  678. };
  679. }());
  680. /**
  681. * @class Ext.menu.MenuMgr
  682. * Provides a common registry of all menu items on a page so that they can be easily accessed by id.
  683. * @singleton
  684. */
  685. Ext.menu.MenuMgr = function(){
  686. var menus,
  687. active,
  688. map,
  689. groups = {},
  690. attached = false,
  691. lastShow = new Date();
  692. // private - called when first menu is created
  693. function init(){
  694. menus = {};
  695. active = new Ext.util.MixedCollection();
  696. map = Ext.getDoc().addKeyListener(27, hideAll);
  697. map.disable();
  698. }
  699. // private
  700. function hideAll(){
  701. if(active && active.length > 0){
  702. var c = active.clone();
  703. c.each(function(m){
  704. m.hide();
  705. });
  706. return true;
  707. }
  708. return false;
  709. }
  710. // private
  711. function onHide(m){
  712. active.remove(m);
  713. if(active.length < 1){
  714. map.disable();
  715. Ext.getDoc().un("mousedown", onMouseDown);
  716. attached = false;
  717. }
  718. }
  719. // private
  720. function onShow(m){
  721. var last = active.last();
  722. lastShow = new Date();
  723. active.add(m);
  724. if(!attached){
  725. map.enable();
  726. Ext.getDoc().on("mousedown", onMouseDown);
  727. attached = true;
  728. }
  729. if(m.parentMenu){
  730. m.getEl().setZIndex(parseInt(m.parentMenu.getEl().getStyle("z-index"), 10) + 3);
  731. m.parentMenu.activeChild = m;
  732. }else if(last && !last.isDestroyed && last.isVisible()){
  733. m.getEl().setZIndex(parseInt(last.getEl().getStyle("z-index"), 10) + 3);
  734. }
  735. }
  736. // private
  737. function onBeforeHide(m){
  738. if(m.activeChild){
  739. m.activeChild.hide();
  740. }
  741. if(m.autoHideTimer){
  742. clearTimeout(m.autoHideTimer);
  743. delete m.autoHideTimer;
  744. }
  745. }
  746. // private
  747. function onBeforeShow(m){
  748. var pm = m.parentMenu;
  749. if(!pm && !m.allowOtherMenus){
  750. hideAll();
  751. }else if(pm && pm.activeChild){
  752. pm.activeChild.hide();
  753. }
  754. }
  755. // private
  756. function onMouseDown(e){
  757. if(lastShow.getElapsed() > 50 && active.length > 0 && !e.getTarget(".x-menu")){
  758. hideAll();
  759. }
  760. }
  761. return {
  762. /**
  763. * Hides all menus that are currently visible
  764. * @return {Boolean} success True if any active menus were hidden.
  765. */
  766. hideAll : function(){
  767. return hideAll();
  768. },
  769. // private
  770. register : function(menu){
  771. if(!menus){
  772. init();
  773. }
  774. menus[menu.id] = menu;
  775. menu.on({
  776. beforehide: onBeforeHide,
  777. hide: onHide,
  778. beforeshow: onBeforeShow,
  779. show: onShow
  780. });
  781. },
  782. /**
  783. * Returns a {@link Ext.menu.Menu} object
  784. * @param {String/Object} menu The string menu id, an existing menu object reference, or a Menu config that will
  785. * be used to generate and return a new Menu instance.
  786. * @return {Ext.menu.Menu} The specified menu, or null if none are found
  787. */
  788. get : function(menu){
  789. if(typeof menu == "string"){ // menu id
  790. if(!menus){ // not initialized, no menus to return
  791. return null;
  792. }
  793. return menus[menu];
  794. }else if(menu.events){ // menu instance
  795. return menu;
  796. }else if(typeof menu.length == 'number'){ // array of menu items?
  797. return new Ext.menu.Menu({items:menu});
  798. }else{ // otherwise, must be a config
  799. return Ext.create(menu, 'menu');
  800. }
  801. },
  802. // private
  803. unregister : function(menu){
  804. delete menus[menu.id];
  805. menu.un("beforehide", onBeforeHide);
  806. menu.un("hide", onHide);
  807. menu.un("beforeshow", onBeforeShow);
  808. menu.un("show", onShow);
  809. },
  810. // private
  811. registerCheckable : function(menuItem){
  812. var g = menuItem.group;
  813. if(g){
  814. if(!groups[g]){
  815. groups[g] = [];
  816. }
  817. groups[g].push(menuItem);
  818. }
  819. },
  820. // private
  821. unregisterCheckable : function(menuItem){
  822. var g = menuItem.group;
  823. if(g){
  824. groups[g].remove(menuItem);
  825. }
  826. },
  827. // private
  828. onCheckChange: function(item, state){
  829. if(item.group && state){
  830. var group = groups[item.group],
  831. i = 0,
  832. len = group.length,
  833. current;
  834. for(; i < len; i++){
  835. current = group[i];
  836. if(current != item){
  837. current.setChecked(false);
  838. }
  839. }
  840. }
  841. },
  842. getCheckedItem : function(groupId){
  843. var g = groups[groupId];
  844. if(g){
  845. for(var i = 0, l = g.length; i < l; i++){
  846. if(g[i].checked){
  847. return g[i];
  848. }
  849. }
  850. }
  851. return null;
  852. },
  853. setCheckedItem : function(groupId, itemId){
  854. var g = groups[groupId];
  855. if(g){
  856. for(var i = 0, l = g.length; i < l; i++){
  857. if(g[i].id == itemId){
  858. g[i].setChecked(true);
  859. }
  860. }
  861. }
  862. return null;
  863. }
  864. };
  865. }();
  866. /**
  867. * @class Ext.menu.BaseItem
  868. * @extends Ext.Component
  869. * The base class for all items that render into menus. BaseItem provides default rendering, activated state
  870. * management and base configuration options shared by all menu components.
  871. * @constructor
  872. * Creates a new BaseItem
  873. * @param {Object} config Configuration options
  874. * @xtype menubaseitem
  875. */
  876. Ext.menu.BaseItem = Ext.extend(Ext.Component, {
  877. /**
  878. * @property parentMenu
  879. * @type Ext.menu.Menu
  880. * The parent Menu of this Item.
  881. */
  882. /**
  883. * @cfg {Function} handler
  884. * A function that will handle the click event of this menu item (optional).
  885. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  886. * <li><code>b</code> : Item<div class="sub-desc">This menu Item.</div></li>
  887. * <li><code>e</code> : EventObject<div class="sub-desc">The click event.</div></li>
  888. * </ul></div>
  889. */
  890. /**
  891. * @cfg {Object} scope
  892. * The scope (<tt><b>this</b></tt> reference) in which the handler function will be called.
  893. */
  894. /**
  895. * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to false)
  896. */
  897. canActivate : false,
  898. /**
  899. * @cfg {String} activeClass The CSS class to use when the item becomes activated (defaults to "x-menu-item-active")
  900. */
  901. activeClass : "x-menu-item-active",
  902. /**
  903. * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to true)
  904. */
  905. hideOnClick : true,
  906. /**
  907. * @cfg {Number} clickHideDelay Length of time in milliseconds to wait before hiding after a click (defaults to 1)
  908. */
  909. clickHideDelay : 1,
  910. // private
  911. ctype : "Ext.menu.BaseItem",
  912. // private
  913. actionMode : "container",
  914. initComponent : function(){
  915. Ext.menu.BaseItem.superclass.initComponent.call(this);
  916. this.addEvents(
  917. /**
  918. * @event click
  919. * Fires when this item is clicked
  920. * @param {Ext.menu.BaseItem} this
  921. * @param {Ext.EventObject} e
  922. */
  923. 'click',
  924. /**
  925. * @event activate
  926. * Fires when this item is activated
  927. * @param {Ext.menu.BaseItem} this
  928. */
  929. 'activate',
  930. /**
  931. * @event deactivate
  932. * Fires when this item is deactivated
  933. * @param {Ext.menu.BaseItem} this
  934. */
  935. 'deactivate'
  936. );
  937. if(this.handler){
  938. this.on("click", this.handler, this.scope);
  939. }
  940. },
  941. // private
  942. onRender : function(container, position){
  943. Ext.menu.BaseItem.superclass.onRender.apply(this, arguments);
  944. if(this.ownerCt && this.ownerCt instanceof Ext.menu.Menu){
  945. this.parentMenu = this.ownerCt;
  946. }else{
  947. this.container.addClass('x-menu-list-item');
  948. this.mon(this.el, {
  949. scope: this,
  950. click: this.onClick,
  951. mouseenter: this.activate,
  952. mouseleave: this.deactivate
  953. });
  954. }
  955. },
  956. /**
  957. * Sets the function that will handle click events for this item (equivalent to passing in the {@link #handler}
  958. * config property). If an existing handler is already registered, it will be unregistered for you.
  959. * @param {Function} handler The function that should be called on click
  960. * @param {Object} scope The scope (<code>this</code> reference) in which the handler function is executed. Defaults to this menu item.
  961. */
  962. setHandler : function(handler, scope){
  963. if(this.handler){
  964. this.un("click", this.handler, this.scope);
  965. }
  966. this.on("click", this.handler = handler, this.scope = scope);
  967. },
  968. // private
  969. onClick : function(e){
  970. if(!this.disabled && this.fireEvent("click", this, e) !== false
  971. && (this.parentMenu && this.parentMenu.fireEvent("itemclick", this, e) !== false)){
  972. this.handleClick(e);
  973. }else{
  974. e.stopEvent();
  975. }
  976. },
  977. // private
  978. activate : function(){
  979. if(this.disabled){
  980. return false;
  981. }
  982. var li = this.container;
  983. li.addClass(this.activeClass);
  984. this.region = li.getRegion().adjust(2, 2, -2, -2);
  985. this.fireEvent("activate", this);
  986. return true;
  987. },
  988. // private
  989. deactivate : function(){
  990. this.container.removeClass(this.activeClass);
  991. this.fireEvent("deactivate", this);
  992. },
  993. // private
  994. shouldDeactivate : function(e){
  995. return !this.region || !this.region.contains(e.getPoint());
  996. },
  997. // private
  998. handleClick : function(e){
  999. var pm = this.parentMenu;
  1000. if(this.hideOnClick){
  1001. if(pm.floating){
  1002. this.clickHideDelayTimer = pm.hide.defer(this.clickHideDelay, pm, [true]);
  1003. }else{
  1004. pm.deactivateActive();
  1005. }
  1006. }
  1007. },
  1008. beforeDestroy: function(){
  1009. clearTimeout(this.clickHideDelayTimer);
  1010. Ext.menu.BaseItem.superclass.beforeDestroy.call(this);
  1011. },
  1012. // private. Do nothing
  1013. expandMenu : Ext.emptyFn,
  1014. // private. Do nothing
  1015. hideMenu : Ext.emptyFn
  1016. });
  1017. Ext.reg('menubaseitem', Ext.menu.BaseItem);/**
  1018. * @class Ext.menu.TextItem
  1019. * @extends Ext.menu.BaseItem
  1020. * Adds a static text string to a menu, usually used as either a heading or group separator.
  1021. * @constructor
  1022. * Creates a new TextItem
  1023. * @param {Object/String} config If config is a string, it is used as the text to display, otherwise it
  1024. * is applied as a config object (and should contain a <tt>text</tt> property).
  1025. * @xtype menutextitem
  1026. */
  1027. Ext.menu.TextItem = Ext.extend(Ext.menu.BaseItem, {
  1028. /**
  1029. * @cfg {String} text The text to display for this item (defaults to '')
  1030. */
  1031. /**
  1032. * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
  1033. */
  1034. hideOnClick : false,
  1035. /**
  1036. * @cfg {String} itemCls The default CSS class to use for text items (defaults to "x-menu-text")
  1037. */
  1038. itemCls : "x-menu-text",
  1039. constructor : function(config) {
  1040. if (typeof config == 'string') {
  1041. config = {
  1042. text: config
  1043. };
  1044. }
  1045. Ext.menu.TextItem.superclass.constructor.call(this, config);
  1046. },
  1047. // private
  1048. onRender : function() {
  1049. var s = document.createElement("span");
  1050. s.className = this.itemCls;
  1051. s.innerHTML = this.text;
  1052. this.el = s;
  1053. Ext.menu.TextItem.superclass.onRender.apply(this, arguments);
  1054. }
  1055. });
  1056. Ext.reg('menutextitem', Ext.menu.TextItem);/**
  1057. * @class Ext.menu.Separator
  1058. * @extends Ext.menu.BaseItem
  1059. * Adds a separator bar to a menu, used to divide logical groups of menu items. Generally you will
  1060. * add one of these by using "-" in you call to add() or in your items config rather than creating one directly.
  1061. * @constructor
  1062. * @param {Object} config Configuration options
  1063. * @xtype menuseparator
  1064. */
  1065. Ext.menu.Separator = Ext.extend(Ext.menu.BaseItem, {
  1066. /**
  1067. * @cfg {String} itemCls The default CSS class to use for separators (defaults to "x-menu-sep")
  1068. */
  1069. itemCls : "x-menu-sep",
  1070. /**
  1071. * @cfg {Boolean} hideOnClick True to hide the containing menu after this item is clicked (defaults to false)
  1072. */
  1073. hideOnClick : false,
  1074. /**
  1075. * @cfg {String} activeClass
  1076. * @hide
  1077. */
  1078. activeClass: '',
  1079. // private
  1080. onRender : function(li){
  1081. var s = document.createElement("span");
  1082. s.className = this.itemCls;
  1083. s.innerHTML = "&#160;";
  1084. this.el = s;
  1085. li.addClass("x-menu-sep-li");
  1086. Ext.menu.Separator.superclass.onRender.apply(this, arguments);
  1087. }
  1088. });
  1089. Ext.reg('menuseparator', Ext.menu.Separator);/**
  1090. * @class Ext.menu.Item
  1091. * @extends Ext.menu.BaseItem
  1092. * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
  1093. * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
  1094. * activation and click handling.
  1095. * @constructor
  1096. * Creates a new Item
  1097. * @param {Object} config Configuration options
  1098. * @xtype menuitem
  1099. */
  1100. Ext.menu.Item = Ext.extend(Ext.menu.BaseItem, {
  1101. /**
  1102. * @property menu
  1103. * @type Ext.menu.Menu
  1104. * The submenu associated with this Item if one was configured.
  1105. */
  1106. /**
  1107. * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
  1108. * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
  1109. */
  1110. /**
  1111. * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
  1112. * icon is specified {@link #iconCls} should not be.
  1113. */
  1114. /**
  1115. * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
  1116. * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
  1117. */
  1118. /**
  1119. * @cfg {String} text The text to display in this item (defaults to '').
  1120. */
  1121. /**
  1122. * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
  1123. */
  1124. /**
  1125. * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
  1126. */
  1127. /**
  1128. * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
  1129. */
  1130. itemCls : 'x-menu-item',
  1131. /**
  1132. * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
  1133. */
  1134. canActivate : true,
  1135. /**
  1136. * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
  1137. */
  1138. showDelay: 200,
  1139. /**
  1140. * @cfg {String} altText The altText to use for the icon, if it exists. Defaults to <tt>''</tt>.
  1141. */
  1142. altText: '',
  1143. // doc'd in BaseItem
  1144. hideDelay: 200,
  1145. // private
  1146. ctype: 'Ext.menu.Item',
  1147. initComponent : function(){
  1148. Ext.menu.Item.superclass.initComponent.call(this);
  1149. if(this.menu){
  1150. // If array of items, turn it into an object config so we
  1151. // can set the ownerCt property in the config
  1152. if (Ext.isArray(this.menu)){
  1153. this.menu = { items: this.menu };
  1154. }
  1155. // An object config will work here, but an instance of a menu
  1156. // will have already setup its ref's and have no effect
  1157. if (Ext.isObject(this.menu)){
  1158. this.menu.ownerCt = this;
  1159. }
  1160. this.menu = Ext.menu.MenuMgr.get(this.menu);
  1161. this.menu.ownerCt = undefined;
  1162. }
  1163. },
  1164. // private
  1165. onRender : function(container, position){
  1166. if (!this.itemTpl) {
  1167. this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
  1168. '<a id="{id}" class="{cls} x-unselectable" hidefocus="true" unselectable="on" href="{href}"',
  1169. '<tpl if="hrefTarget">',
  1170. ' target="{hrefTarget}"',
  1171. '</tpl>',
  1172. '>',
  1173. '<img alt="{altText}" src="{icon}" class="x-menu-item-icon {iconCls}"/>',
  1174. '<span class="x-menu-item-text">{text}</span>',
  1175. '</a>'
  1176. );
  1177. }
  1178. var a = this.getTemplateArgs();
  1179. this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
  1180. this.iconEl = this.el.child('img.x-menu-item-icon');
  1181. this.textEl = this.el.child('.x-menu-item-text');
  1182. if(!this.href) { // if no link defined, prevent the default anchor event
  1183. this.mon(this.el, 'click', Ext.emptyFn, null, { preventDefault: true });
  1184. }
  1185. Ext.menu.Item.superclass.onRender.call(this, container, position);
  1186. },
  1187. getTemplateArgs: function() {
  1188. return {
  1189. id: this.id,
  1190. cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
  1191. href: this.href || '#',
  1192. hrefTarget: this.hrefTarget,
  1193. icon: this.icon || Ext.BLANK_IMAGE_URL,
  1194. iconCls: this.iconCls || '',
  1195. text: this.itemText||this.text||'&#160;',
  1196. altText: this.altText || ''
  1197. };
  1198. },
  1199. /**
  1200. * Sets the text to display in this menu item
  1201. * @param {String} text The text to display
  1202. */
  1203. setText : function(text){
  1204. this.text = text||'&#160;';
  1205. if(this.rendered){
  1206. this.textEl.update(this.text);
  1207. this.parentMenu.layout.doAutoSize();
  1208. }
  1209. },
  1210. /**
  1211. * Sets the CSS class to apply to the item's icon element
  1212. * @param {String} cls The CSS class to apply
  1213. */
  1214. setIconClass : function(cls){
  1215. var oldCls = this.iconCls;
  1216. this.iconCls = cls;
  1217. if(this.rendered){
  1218. this.iconEl.replaceClass(oldCls, this.iconCls);
  1219. }
  1220. },
  1221. //private
  1222. beforeDestroy: function(){
  1223. clearTimeout(this.showTimer);
  1224. clearTimeout(this.hideTimer);
  1225. if (this.menu){
  1226. delete this.menu.ownerCt;
  1227. this.menu.destroy();
  1228. }
  1229. Ext.menu.Item.superclass.beforeDestroy.call(this);
  1230. },
  1231. // private
  1232. handleClick : function(e){
  1233. if(!this.href){ // if no link defined, stop the event automatically
  1234. e.stopEvent();
  1235. }
  1236. Ext.menu.Item.superclass.handleClick.apply(this, arguments);
  1237. },
  1238. // private
  1239. activate : function(autoExpand){
  1240. if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
  1241. this.focus();
  1242. if(autoExpand){
  1243. this.expandMenu();
  1244. }
  1245. }
  1246. return true;
  1247. },
  1248. // private
  1249. shouldDeactivate : function(e){
  1250. if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
  1251. if(this.menu && this.menu.isVisible()){
  1252. return !this.menu.getEl().getRegion().contains(e.getPoint());
  1253. }
  1254. return true;
  1255. }
  1256. return false;
  1257. },
  1258. // private
  1259. deactivate : function(){
  1260. Ext.menu.Item.superclass.deactivate.apply(this, arguments);
  1261. this.hideMenu();
  1262. },
  1263. // private
  1264. expandMenu : function(autoActivate){
  1265. if(!this.disabled && this.menu){
  1266. clearTimeout(this.hideTimer);
  1267. delete this.hideTimer;
  1268. if(!this.menu.isVisible() && !this.showTimer){
  1269. this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
  1270. }else if (this.menu.isVisible() && autoActivate){
  1271. this.menu.tryActivate(0, 1);
  1272. }
  1273. }
  1274. },
  1275. // private
  1276. deferExpand : function(autoActivate){
  1277. delete this.showTimer;
  1278. this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
  1279. if(autoActivate){
  1280. this.menu.tryActivate(0, 1);
  1281. }
  1282. },
  1283. // private
  1284. hideMenu : function(){
  1285. clearTimeout(this.showTimer);
  1286. delete this.showTimer;
  1287. if(!this.hideTimer && this.menu && this.menu.isVisible()){
  1288. this.hideTimer = this.deferHide.defer(this.hideDelay, this);
  1289. }
  1290. },
  1291. // private
  1292. deferHide : function(){
  1293. delete this.hideTimer;
  1294. if(this.menu.over){
  1295. this.parentMenu.setActiveItem(this, false);
  1296. }else{
  1297. this.menu.hide();
  1298. }
  1299. }
  1300. });
  1301. Ext.reg('menuitem', Ext.menu.Item);/**
  1302. * @class Ext.menu.CheckItem
  1303. * @extends Ext.menu.Item
  1304. * Adds a menu item that contains a checkbox by default, but can also be part of a radio group.
  1305. * @constructor
  1306. * Creates a new CheckItem
  1307. * @param {Object} config Configuration options
  1308. * @xtype menucheckitem
  1309. */
  1310. Ext.menu.CheckItem = Ext.extend(Ext.menu.Item, {
  1311. /**
  1312. * @cfg {String} group
  1313. * All check items with the same group name will automatically be grouped into a single-select
  1314. * radio button group (defaults to '')
  1315. */
  1316. /**
  1317. * @cfg {String} itemCls The default CSS class to use for check items (defaults to "x-menu-item x-menu-check-item")
  1318. */
  1319. itemCls : "x-menu-item x-menu-check-item",
  1320. /**
  1321. * @cfg {String} groupClass The default CSS class to use for radio group check items (defaults to "x-menu-group-item")
  1322. */
  1323. groupClass : "x-menu-group-item",
  1324. /**
  1325. * @cfg {Boolean} checked True to initialize this checkbox as checked (defaults to false). Note that
  1326. * if this checkbox is part of a radio group (group = true) only the first item in the group that is
  1327. * initialized with checked = true will be rendered as checked.
  1328. */
  1329. checked: false,
  1330. // private
  1331. ctype: "Ext.menu.CheckItem",
  1332. initComponent : function(){
  1333. Ext.menu.CheckItem.superclass.initComponent.call(this);
  1334. this.addEvents(
  1335. /**
  1336. * @event beforecheckchange
  1337. * Fires before the checked value is set, providing an opportunity to cancel if needed
  1338. * @param {Ext.menu.CheckItem} this
  1339. * @param {Boolean} checked The new checked value that will be set
  1340. */
  1341. "beforecheckchange" ,
  1342. /**
  1343. * @event checkchange
  1344. * Fires after the checked value has been set
  1345. * @param {Ext.menu.CheckItem} this
  1346. * @param {Boolean} checked The checked value that was set
  1347. */
  1348. "checkchange"
  1349. );
  1350. /**
  1351. * A function that handles the checkchange event. The function is undefined by default, but if an implementation
  1352. * is provided, it will be called automatically when the checkchange event fires.
  1353. * @param {Ext.menu.CheckItem} this
  1354. * @param {Boolean} checked The checked value that was set
  1355. * @method checkHandler
  1356. */
  1357. if(this.checkHandler){
  1358. this.on('checkchange', this.checkHandler, this.scope);
  1359. }
  1360. Ext.menu.MenuMgr.registerCheckable(this);
  1361. },
  1362. // private
  1363. onRender : function(c){
  1364. Ext.menu.CheckItem.superclass.onRender.apply(this, arguments);
  1365. if(this.group){
  1366. this.el.addClass(this.groupClass);
  1367. }
  1368. if(this.checked){
  1369. this.checked = false;
  1370. this.setChecked(true, true);
  1371. }
  1372. },
  1373. // private
  1374. destroy : function(){
  1375. Ext.menu.MenuMgr.unregisterCheckable(this);
  1376. Ext.menu.CheckItem.superclass.destroy.apply(this, arguments);
  1377. },
  1378. /**
  1379. * Set the checked state of this item
  1380. * @param {Boolean} checked The new checked value
  1381. * @param {Boolean} suppressEvent (optional) True to prevent the checkchange event from firing (defaults to false)
  1382. */
  1383. setChecked : function(state, suppressEvent){
  1384. var suppress = suppressEvent === true;
  1385. if(this.checked != state && (suppress || this.fireEvent("beforecheckchange", this, state) !== false)){
  1386. Ext.menu.MenuMgr.onCheckChange(this, state);
  1387. if(this.container){
  1388. this.container[state ? "addClass" : "removeClass"]("x-menu-item-checked");
  1389. }
  1390. this.checked = state;
  1391. if(!suppress){
  1392. this.fireEvent("checkchange", this, state);
  1393. }
  1394. }
  1395. },
  1396. // private
  1397. handleClick : function(e){
  1398. if(!this.disabled && !(this.checked && this.group)){// disable unselect on radio item
  1399. this.setChecked(!this.checked);
  1400. }
  1401. Ext.menu.CheckItem.superclass.handleClick.apply(this, arguments);
  1402. }
  1403. });
  1404. Ext.reg('menucheckitem', Ext.menu.CheckItem);/**
  1405. * @class Ext.menu.DateMenu
  1406. * @extends Ext.menu.Menu
  1407. * <p>A menu containing an {@link Ext.DatePicker} Component.</p>
  1408. * <p>Notes:</p><div class="mdetail-params"><ul>
  1409. * <li>Although not listed here, the <b>constructor</b> for this class
  1410. * accepts all of the configuration options of <b>{@link Ext.DatePicker}</b>.</li>
  1411. * <li>If subclassing DateMenu, any configuration options for the DatePicker must be
  1412. * applied to the <tt><b>initialConfig</b></tt> property of the DateMenu.
  1413. * Applying {@link Ext.DatePicker DatePicker} configuration settings to
  1414. * <b><tt>this</tt></b> will <b>not</b> affect the DatePicker's configuration.</li>
  1415. * </ul></div>
  1416. * @xtype datemenu
  1417. */
  1418. Ext.menu.DateMenu = Ext.extend(Ext.menu.Menu, {
  1419. /**
  1420. * @cfg {Boolean} enableScrolling
  1421. * @hide
  1422. */
  1423. enableScrolling : false,
  1424. /**
  1425. * @cfg {Function} handler
  1426. * Optional. A function that will handle the select event of this menu.
  1427. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  1428. * <li><code>picker</code> : DatePicker<div class="sub-desc">The Ext.DatePicker.</div></li>
  1429. * <li><code>date</code> : Date<div class="sub-desc">The selected date.</div></li>
  1430. * </ul></div>
  1431. */
  1432. /**
  1433. * @cfg {Object} scope
  1434. * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
  1435. * function will be called. Defaults to this DateMenu instance.
  1436. */
  1437. /**
  1438. * @cfg {Boolean} hideOnClick
  1439. * False to continue showing the menu after a date is selected, defaults to true.
  1440. */
  1441. hideOnClick : true,
  1442. /**
  1443. * @cfg {String} pickerId
  1444. * An id to assign to the underlying date picker. Defaults to <tt>null</tt>.
  1445. */
  1446. pickerId : null,
  1447. /**
  1448. * @cfg {Number} maxHeight
  1449. * @hide
  1450. */
  1451. /**
  1452. * @cfg {Number} scrollIncrement
  1453. * @hide
  1454. */
  1455. /**
  1456. * The {@link Ext.DatePicker} instance for this DateMenu
  1457. * @property picker
  1458. * @type DatePicker
  1459. */
  1460. cls : 'x-date-menu',
  1461. /**
  1462. * @event click
  1463. * @hide
  1464. */
  1465. /**
  1466. * @event itemclick
  1467. * @hide
  1468. */
  1469. initComponent : function(){
  1470. this.on('beforeshow', this.onBeforeShow, this);
  1471. if(this.strict = (Ext.isIE7 && Ext.isStrict)){
  1472. this.on('show', this.onShow, this, {single: true, delay: 20});
  1473. }
  1474. Ext.apply(this, {
  1475. plain: true,
  1476. showSeparator: false,
  1477. items: this.picker = new Ext.DatePicker(Ext.applyIf({
  1478. internalRender: this.strict || !Ext.isIE9m,
  1479. ctCls: 'x-menu-date-item',
  1480. id: this.pickerId
  1481. }, this.initialConfig))
  1482. });
  1483. this.picker.purgeListeners();
  1484. Ext.menu.DateMenu.superclass.initComponent.call(this);
  1485. /**
  1486. * @event select
  1487. * Fires when a date is selected from the {@link #picker Ext.DatePicker}
  1488. * @param {DatePicker} picker The {@link #picker Ext.DatePicker}
  1489. * @param {Date} date The selected date
  1490. */
  1491. this.relayEvents(this.picker, ['select']);
  1492. this.on('show', this.picker.focus, this.picker);
  1493. this.on('select', this.menuHide, this);
  1494. if(this.handler){
  1495. this.on('select', this.handler, this.scope || this);
  1496. }
  1497. },
  1498. menuHide : function() {
  1499. if(this.hideOnClick){
  1500. this.hide(true);
  1501. }
  1502. },
  1503. onBeforeShow : function(){
  1504. if(this.picker){
  1505. this.picker.hideMonthPicker(true);
  1506. }
  1507. },
  1508. onShow : function(){
  1509. var el = this.picker.getEl();
  1510. el.setWidth(el.getWidth()); //nasty hack for IE7 strict mode
  1511. }
  1512. });
  1513. Ext.reg('datemenu', Ext.menu.DateMenu);
  1514. /**
  1515. * @class Ext.menu.ColorMenu
  1516. * @extends Ext.menu.Menu
  1517. * <p>A menu containing a {@link Ext.ColorPalette} Component.</p>
  1518. * <p>Notes:</p><div class="mdetail-params"><ul>
  1519. * <li>Although not listed here, the <b>constructor</b> for this class
  1520. * accepts all of the configuration options of <b>{@link Ext.ColorPalette}</b>.</li>
  1521. * <li>If subclassing ColorMenu, any configuration options for the ColorPalette must be
  1522. * applied to the <tt><b>initialConfig</b></tt> property of the ColorMenu.
  1523. * Applying {@link Ext.ColorPalette ColorPalette} configuration settings to
  1524. * <b><tt>this</tt></b> will <b>not</b> affect the ColorPalette's configuration.</li>
  1525. * </ul></div> *
  1526. * @xtype colormenu
  1527. */
  1528. Ext.menu.ColorMenu = Ext.extend(Ext.menu.Menu, {
  1529. /**
  1530. * @cfg {Boolean} enableScrolling
  1531. * @hide
  1532. */
  1533. enableScrolling : false,
  1534. /**
  1535. * @cfg {Function} handler
  1536. * Optional. A function that will handle the select event of this menu.
  1537. * The handler is passed the following parameters:<div class="mdetail-params"><ul>
  1538. * <li><code>palette</code> : ColorPalette<div class="sub-desc">The {@link #palette Ext.ColorPalette}.</div></li>
  1539. * <li><code>color</code> : String<div class="sub-desc">The 6-digit color hex code (without the # symbol).</div></li>
  1540. * </ul></div>
  1541. */
  1542. /**
  1543. * @cfg {Object} scope
  1544. * The scope (<tt><b>this</b></tt> reference) in which the <code>{@link #handler}</code>
  1545. * function will be called. Defaults to this ColorMenu instance.
  1546. */
  1547. /**
  1548. * @cfg {Boolean} hideOnClick
  1549. * False to continue showing the menu after a color is selected, defaults to true.
  1550. */
  1551. hideOnClick : true,
  1552. cls : 'x-color-menu',
  1553. /**
  1554. * @cfg {String} paletteId
  1555. * An id to assign to the underlying color palette. Defaults to <tt>null</tt>.
  1556. */
  1557. paletteId : null,
  1558. /**
  1559. * @cfg {Number} maxHeight
  1560. * @hide
  1561. */
  1562. /**
  1563. * @cfg {Number} scrollIncrement
  1564. * @hide
  1565. */
  1566. /**
  1567. * @property palette
  1568. * @type ColorPalette
  1569. * The {@link Ext.ColorPalette} instance for this ColorMenu
  1570. */
  1571. /**
  1572. * @event click
  1573. * @hide
  1574. */
  1575. /**
  1576. * @event itemclick
  1577. * @hide
  1578. */
  1579. initComponent : function(){
  1580. Ext.apply(this, {
  1581. plain: true,
  1582. showSeparator: false,
  1583. items: this.palette = new Ext.ColorPalette(Ext.applyIf({
  1584. id: this.paletteId
  1585. }, this.initialConfig))
  1586. });
  1587. this.palette.purgeListeners();
  1588. Ext.menu.ColorMenu.superclass.initComponent.call(this);
  1589. /**
  1590. * @event select
  1591. * Fires when a color is selected from the {@link #palette Ext.ColorPalette}
  1592. * @param {Ext.ColorPalette} palette The {@link #palette Ext.ColorPalette}
  1593. * @param {String} color The 6-digit color hex code (without the # symbol)
  1594. */
  1595. this.relayEvents(this.palette, ['select']);
  1596. this.on('select', this.menuHide, this);
  1597. if(this.handler){
  1598. this.on('select', this.handler, this.scope || this);
  1599. }
  1600. },
  1601. menuHide : function(){
  1602. if(this.hideOnClick){
  1603. this.hide(true);
  1604. }
  1605. }
  1606. });
  1607. Ext.reg('colormenu', Ext.menu.ColorMenu);