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.

734 lines
28 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-menu-Menu'>/**
  19. </span> * @class Ext.menu.Menu
  20. * @extends Ext.Container
  21. * &lt;p&gt;A menu object. This is the container to which you may add menu items. Menu can also serve as a base class
  22. * when you want a specialized menu based off of another component (like {@link Ext.menu.DateMenu} for example).&lt;/p&gt;
  23. * &lt;p&gt;Menus may contain either {@link Ext.menu.Item menu items}, or general {@link Ext.Component Component}s.&lt;/p&gt;
  24. * &lt;p&gt;To make a contained general {@link Ext.Component Component} line up with other {@link Ext.menu.Item menu items}
  25. * specify &lt;tt&gt;iconCls: 'no-icon'&lt;/tt&gt;. This reserves a space for an icon, and indents the Component in line
  26. * with the other menu items. See {@link Ext.form.ComboBox}.{@link Ext.form.ComboBox#getListParent getListParent}
  27. * for an example.&lt;/p&gt;
  28. * &lt;p&gt;By default, Menus are absolutely positioned, floating Components. By configuring a Menu with
  29. * &lt;b&gt;&lt;tt&gt;{@link #floating}:false&lt;/tt&gt;&lt;/b&gt;, a Menu may be used as child of a Container.&lt;/p&gt;
  30. *
  31. * @xtype menu
  32. */
  33. Ext.menu.Menu = Ext.extend(Ext.Container, {
  34. <span id='Ext-menu-Menu-cfg-defaults'> /**
  35. </span> * @cfg {Object} defaults
  36. * A config object that will be applied to all items added to this container either via the {@link #items}
  37. * config or via the {@link #add} method. The defaults config can contain any number of
  38. * name/value property pairs to be added to each item, and should be valid for the types of items
  39. * being added to the menu.
  40. */
  41. <span id='Ext-menu-Menu-cfg-items'> /**
  42. </span> * @cfg {Mixed} items
  43. * An array of items to be added to this menu. Menus may contain either {@link Ext.menu.Item menu items},
  44. * or general {@link Ext.Component Component}s.
  45. */
  46. <span id='Ext-menu-Menu-cfg-minWidth'> /**
  47. </span> * @cfg {Number} minWidth The minimum width of the menu in pixels (defaults to 120)
  48. */
  49. minWidth : 120,
  50. <span id='Ext-menu-Menu-cfg-shadow'> /**
  51. </span> * @cfg {Boolean/String} shadow True or 'sides' for the default effect, 'frame' for 4-way shadow, and 'drop'
  52. * for bottom-right shadow (defaults to 'sides')
  53. */
  54. shadow : 'sides',
  55. <span id='Ext-menu-Menu-cfg-subMenuAlign'> /**
  56. </span> * @cfg {String} subMenuAlign The {@link Ext.Element#alignTo} anchor position value to use for submenus of
  57. * this menu (defaults to 'tl-tr?')
  58. */
  59. subMenuAlign : 'tl-tr?',
  60. <span id='Ext-menu-Menu-cfg-defaultAlign'> /**
  61. </span> * @cfg {String} defaultAlign The default {@link Ext.Element#alignTo} anchor position value for this menu
  62. * relative to its element of origin (defaults to 'tl-bl?')
  63. */
  64. defaultAlign : 'tl-bl?',
  65. <span id='Ext-menu-Menu-cfg-allowOtherMenus'> /**
  66. </span> * @cfg {Boolean} allowOtherMenus True to allow multiple menus to be displayed at the same time (defaults to false)
  67. */
  68. allowOtherMenus : false,
  69. <span id='Ext-menu-Menu-cfg-ignoreParentClicks'> /**
  70. </span> * @cfg {Boolean} ignoreParentClicks True to ignore clicks on any item in this menu that is a parent item (displays
  71. * a submenu) so that the submenu is not dismissed when clicking the parent item (defaults to false).
  72. */
  73. ignoreParentClicks : false,
  74. <span id='Ext-menu-Menu-cfg-enableScrolling'> /**
  75. </span> * @cfg {Boolean} enableScrolling True to allow the menu container to have scroller controls if the menu is too long (defaults to true).
  76. */
  77. enableScrolling : true,
  78. <span id='Ext-menu-Menu-cfg-maxHeight'> /**
  79. </span> * @cfg {Number} maxHeight The maximum height of the menu. Only applies when enableScrolling is set to True (defaults to null).
  80. */
  81. maxHeight : null,
  82. <span id='Ext-menu-Menu-cfg-scrollIncrement'> /**
  83. </span> * @cfg {Number} scrollIncrement The amount to scroll the menu. Only applies when enableScrolling is set to True (defaults to 24).
  84. */
  85. scrollIncrement : 24,
  86. <span id='Ext-menu-Menu-cfg-showSeparator'> /**
  87. </span> * @cfg {Boolean} showSeparator True to show the icon separator. (defaults to true).
  88. */
  89. showSeparator : true,
  90. <span id='Ext-menu-Menu-cfg-defaultOffsets'> /**
  91. </span> * @cfg {Array} defaultOffsets An array specifying the [x, y] offset in pixels by which to
  92. * change the default Menu popup position after aligning according to the {@link #defaultAlign}
  93. * configuration. Defaults to &lt;tt&gt;[0, 0]&lt;/tt&gt;.
  94. */
  95. defaultOffsets : [0, 0],
  96. <span id='Ext-menu-Menu-cfg-plain'> /**
  97. </span> * @cfg {Boolean} plain
  98. * True to remove the incised line down the left side of the menu. Defaults to &lt;tt&gt;false&lt;/tt&gt;.
  99. */
  100. plain : false,
  101. <span id='Ext-menu-Menu-cfg-floating'> /**
  102. </span> * @cfg {Boolean} floating
  103. * &lt;p&gt;By default, a Menu configured as &lt;b&gt;&lt;code&gt;floating:true&lt;/code&gt;&lt;/b&gt;
  104. * will be rendered as an {@link Ext.Layer} (an absolutely positioned,
  105. * floating Component with zindex=15000).
  106. * If configured as &lt;b&gt;&lt;code&gt;floating:false&lt;/code&gt;&lt;/b&gt;, the Menu may be
  107. * used as child item of another Container instead of a free-floating
  108. * {@link Ext.Layer Layer}.
  109. */
  110. floating : true,
  111. <span id='Ext-menu-Menu-cfg-zIndex'> /**
  112. </span> * @cfg {Number} zIndex
  113. * zIndex to use when the menu is floating.
  114. */
  115. zIndex: 15000,
  116. <span id='Ext-menu-Menu-property-hidden'> // private
  117. </span> hidden : true,
  118. <span id='Ext-menu-Menu-cfg-layout'> /**
  119. </span> * @cfg {String/Object} layout
  120. * This class assigns a default layout (&lt;code&gt;layout:'&lt;b&gt;menu&lt;/b&gt;'&lt;/code&gt;).
  121. * Developers &lt;i&gt;may&lt;/i&gt; override this configuration option if another layout is required.
  122. * See {@link Ext.Container#layout} for additional information.
  123. */
  124. layout : 'menu',
  125. <span id='Ext-menu-Menu-property-scrollerHeight'><span id='Ext-menu-Menu-cfg-hideMode'> hideMode : 'offsets', // Important for laying out Components
  126. </span></span> scrollerHeight : 8,
  127. <span id='Ext-menu-Menu-cfg-defaultType'><span id='Ext-menu-Menu-property-autoLayout'> autoLayout : true, // Provided for backwards compat
  128. </span></span> defaultType : 'menuitem',
  129. <span id='Ext-menu-Menu-cfg-bufferResize'> bufferResize : false,
  130. </span>
  131. <span id='Ext-menu-Menu-method-initComponent'> initComponent : function(){
  132. </span> if(Ext.isArray(this.initialConfig)){
  133. Ext.apply(this, {items:this.initialConfig});
  134. }
  135. this.addEvents(
  136. <span id='Ext-menu-Menu-event-click'> /**
  137. </span> * @event click
  138. * Fires when this menu is clicked (or when the enter key is pressed while it is active)
  139. * @param {Ext.menu.Menu} this
  140. * @param {Ext.menu.Item} menuItem The menu item that was clicked
  141. * @param {Ext.EventObject} e
  142. */
  143. 'click',
  144. <span id='Ext-menu-Menu-event-mouseover'> /**
  145. </span> * @event mouseover
  146. * Fires when the mouse is hovering over this menu
  147. * @param {Ext.menu.Menu} this
  148. * @param {Ext.EventObject} e
  149. * @param {Ext.menu.Item} menuItem The menu item that was clicked
  150. */
  151. 'mouseover',
  152. <span id='Ext-menu-Menu-event-mouseout'> /**
  153. </span> * @event mouseout
  154. * Fires when the mouse exits this menu
  155. * @param {Ext.menu.Menu} this
  156. * @param {Ext.EventObject} e
  157. * @param {Ext.menu.Item} menuItem The menu item that was clicked
  158. */
  159. 'mouseout',
  160. <span id='Ext-menu-Menu-event-itemclick'> /**
  161. </span> * @event itemclick
  162. * Fires when a menu item contained in this menu is clicked
  163. * @param {Ext.menu.BaseItem} baseItem The BaseItem that was clicked
  164. * @param {Ext.EventObject} e
  165. */
  166. 'itemclick'
  167. );
  168. Ext.menu.MenuMgr.register(this);
  169. if(this.floating){
  170. Ext.EventManager.onWindowResize(this.hide, this);
  171. }else{
  172. if(this.initialConfig.hidden !== false){
  173. this.hidden = false;
  174. }
  175. this.internalDefaults = {hideOnClick: false};
  176. }
  177. Ext.menu.Menu.superclass.initComponent.call(this);
  178. if(this.autoLayout){
  179. var fn = this.doLayout.createDelegate(this, []);
  180. this.on({
  181. add: fn,
  182. remove: fn
  183. });
  184. }
  185. },
  186. <span id='Ext-menu-Menu-method-getLayoutTarget'> //private
  187. </span> getLayoutTarget : function() {
  188. return this.ul;
  189. },
  190. <span id='Ext-menu-Menu-method-onRender'> // private
  191. </span> onRender : function(ct, position){
  192. if(!ct){
  193. ct = Ext.getBody();
  194. }
  195. var dh = {
  196. id: this.getId(),
  197. cls: 'x-menu ' + ((this.floating) ? 'x-menu-floating x-layer ' : '') + (this.cls || '') + (this.plain ? ' x-menu-plain' : '') + (this.showSeparator ? '' : ' x-menu-nosep'),
  198. style: this.style,
  199. cn: [
  200. {tag: 'a', cls: 'x-menu-focus', href: '#', onclick: 'return false;', tabIndex: '-1'},
  201. {tag: 'ul', cls: 'x-menu-list'}
  202. ]
  203. };
  204. if(this.floating){
  205. this.el = new Ext.Layer({
  206. shadow: this.shadow,
  207. dh: dh,
  208. constrain: false,
  209. parentEl: ct,
  210. zindex: this.zIndex
  211. });
  212. }else{
  213. this.el = ct.createChild(dh);
  214. }
  215. Ext.menu.Menu.superclass.onRender.call(this, ct, position);
  216. if(!this.keyNav){
  217. this.keyNav = new Ext.menu.MenuNav(this);
  218. }
  219. // generic focus element
  220. this.focusEl = this.el.child('a.x-menu-focus');
  221. this.ul = this.el.child('ul.x-menu-list');
  222. this.mon(this.ul, {
  223. scope: this,
  224. click: this.onClick,
  225. mouseover: this.onMouseOver,
  226. mouseout: this.onMouseOut
  227. });
  228. if(this.enableScrolling){
  229. this.mon(this.el, {
  230. scope: this,
  231. delegate: '.x-menu-scroller',
  232. click: this.onScroll,
  233. mouseover: this.deactivateActive
  234. });
  235. }
  236. },
  237. <span id='Ext-menu-Menu-method-findTargetItem'> // private
  238. </span> findTargetItem : function(e){
  239. var t = e.getTarget('.x-menu-list-item', this.ul, true);
  240. if(t &amp;&amp; t.menuItemId){
  241. return this.items.get(t.menuItemId);
  242. }
  243. },
  244. <span id='Ext-menu-Menu-method-onClick'> // private
  245. </span> onClick : function(e){
  246. var t = this.findTargetItem(e);
  247. if(t){
  248. if(t.isFormField){
  249. this.setActiveItem(t);
  250. }else if(t instanceof Ext.menu.BaseItem){
  251. if(t.menu &amp;&amp; this.ignoreParentClicks){
  252. t.expandMenu();
  253. e.preventDefault();
  254. }else if(t.onClick){
  255. t.onClick(e);
  256. this.fireEvent('click', this, t, e);
  257. }
  258. }
  259. }
  260. },
  261. <span id='Ext-menu-Menu-method-setActiveItem'> // private
  262. </span> setActiveItem : function(item, autoExpand){
  263. if(item != this.activeItem){
  264. this.deactivateActive();
  265. if((this.activeItem = item).isFormField){
  266. item.focus();
  267. }else{
  268. item.activate(autoExpand);
  269. }
  270. }else if(autoExpand){
  271. item.expandMenu();
  272. }
  273. },
  274. <span id='Ext-menu-Menu-method-deactivateActive'> deactivateActive : function(){
  275. </span> var a = this.activeItem;
  276. if(a){
  277. if(a.isFormField){
  278. //Fields cannot deactivate, but Combos must collapse
  279. if(a.collapse){
  280. a.collapse();
  281. }
  282. }else{
  283. a.deactivate();
  284. }
  285. delete this.activeItem;
  286. }
  287. },
  288. <span id='Ext-menu-Menu-method-tryActivate'> // private
  289. </span> tryActivate : function(start, step){
  290. var items = this.items;
  291. for(var i = start, len = items.length; i &gt;= 0 &amp;&amp; i &lt; len; i+= step){
  292. var item = items.get(i);
  293. if(item.isVisible() &amp;&amp; !item.disabled &amp;&amp; (item.canActivate || item.isFormField)){
  294. this.setActiveItem(item, false);
  295. return item;
  296. }
  297. }
  298. return false;
  299. },
  300. <span id='Ext-menu-Menu-method-onMouseOver'> // private
  301. </span> onMouseOver : function(e){
  302. var t = this.findTargetItem(e);
  303. if(t){
  304. if(t.canActivate &amp;&amp; !t.disabled){
  305. this.setActiveItem(t, true);
  306. }
  307. }
  308. this.over = true;
  309. this.fireEvent('mouseover', this, e, t);
  310. },
  311. <span id='Ext-menu-Menu-method-onMouseOut'> // private
  312. </span> onMouseOut : function(e){
  313. var t = this.findTargetItem(e);
  314. if(t){
  315. if(t == this.activeItem &amp;&amp; t.shouldDeactivate &amp;&amp; t.shouldDeactivate(e)){
  316. this.activeItem.deactivate();
  317. delete this.activeItem;
  318. }
  319. }
  320. this.over = false;
  321. this.fireEvent('mouseout', this, e, t);
  322. },
  323. <span id='Ext-menu-Menu-method-onScroll'> // private
  324. </span> onScroll : function(e, t){
  325. if(e){
  326. e.stopEvent();
  327. }
  328. var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top');
  329. ul.scrollTop += this.scrollIncrement * (top ? -1 : 1);
  330. if(top ? ul.scrollTop &lt;= 0 : ul.scrollTop + this.activeMax &gt;= ul.scrollHeight){
  331. this.onScrollerOut(null, t);
  332. }
  333. },
  334. <span id='Ext-menu-Menu-method-onScrollerIn'> // private
  335. </span> onScrollerIn : function(e, t){
  336. var ul = this.ul.dom, top = Ext.fly(t).is('.x-menu-scroller-top');
  337. if(top ? ul.scrollTop &gt; 0 : ul.scrollTop + this.activeMax &lt; ul.scrollHeight){
  338. Ext.fly(t).addClass(['x-menu-item-active', 'x-menu-scroller-active']);
  339. }
  340. },
  341. <span id='Ext-menu-Menu-method-onScrollerOut'> // private
  342. </span> onScrollerOut : function(e, t){
  343. Ext.fly(t).removeClass(['x-menu-item-active', 'x-menu-scroller-active']);
  344. },
  345. <span id='Ext-menu-Menu-method-show'> /**
  346. </span> * If &lt;code&gt;{@link #floating}=true&lt;/code&gt;, shows this menu relative to
  347. * another element using {@link #showat}, otherwise uses {@link Ext.Component#show}.
  348. * @param {Mixed} element The element to align to
  349. * @param {String} position (optional) The {@link Ext.Element#alignTo} anchor position to use in aligning to
  350. * the element (defaults to this.defaultAlign)
  351. * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
  352. */
  353. show : function(el, pos, parentMenu){
  354. if(this.floating){
  355. this.parentMenu = parentMenu;
  356. if(!this.el){
  357. this.render();
  358. this.doLayout(false, true);
  359. }
  360. this.showAt(this.el.getAlignToXY(el, pos || this.defaultAlign, this.defaultOffsets), parentMenu);
  361. }else{
  362. Ext.menu.Menu.superclass.show.call(this);
  363. }
  364. },
  365. <span id='Ext-menu-Menu-method-showAt'> /**
  366. </span> * Displays this menu at a specific xy position and fires the 'show' event if a
  367. * handler for the 'beforeshow' event does not return false cancelling the operation.
  368. * @param {Array} xyPosition Contains X &amp; Y [x, y] values for the position at which to show the menu (coordinates are page-based)
  369. * @param {Ext.menu.Menu} parentMenu (optional) This menu's parent menu, if applicable (defaults to undefined)
  370. */
  371. showAt : function(xy, parentMenu){
  372. if(this.fireEvent('beforeshow', this) !== false){
  373. this.parentMenu = parentMenu;
  374. if(!this.el){
  375. this.render();
  376. }
  377. if(this.enableScrolling){
  378. // set the position so we can figure out the constrain value.
  379. this.el.setXY(xy);
  380. //constrain the value, keep the y coordinate the same
  381. xy[1] = this.constrainScroll(xy[1]);
  382. xy = [this.el.adjustForConstraints(xy)[0], xy[1]];
  383. }else{
  384. //constrain to the viewport.
  385. xy = this.el.adjustForConstraints(xy);
  386. }
  387. this.el.setXY(xy);
  388. this.el.show();
  389. Ext.menu.Menu.superclass.onShow.call(this);
  390. if(Ext.isIE9m){
  391. // internal event, used so we don't couple the layout to the menu
  392. this.fireEvent('autosize', this);
  393. if(!Ext.isIE8){
  394. this.el.repaint();
  395. }
  396. }
  397. this.hidden = false;
  398. this.focus();
  399. this.fireEvent('show', this);
  400. }
  401. },
  402. <span id='Ext-menu-Menu-method-constrainScroll'> constrainScroll : function(y){
  403. </span> var max, full = this.ul.setHeight('auto').getHeight(),
  404. returnY = y, normalY, parentEl, scrollTop, viewHeight;
  405. if(this.floating){
  406. parentEl = Ext.fly(this.el.dom.parentNode);
  407. scrollTop = parentEl.getScroll().top;
  408. viewHeight = parentEl.getViewSize().height;
  409. //Normalize y by the scroll position for the parent element. Need to move it into the coordinate space
  410. //of the view.
  411. normalY = y - scrollTop;
  412. max = this.maxHeight ? this.maxHeight : viewHeight - normalY;
  413. if(full &gt; viewHeight) {
  414. max = viewHeight;
  415. //Set returnY equal to (0,0) in view space by reducing y by the value of normalY
  416. returnY = y - normalY;
  417. } else if(max &lt; full) {
  418. returnY = y - (full - max);
  419. max = full;
  420. }
  421. }else{
  422. max = this.getHeight();
  423. }
  424. // Always respect maxHeight
  425. if (this.maxHeight){
  426. max = Math.min(this.maxHeight, max);
  427. }
  428. if(full &gt; max &amp;&amp; max &gt; 0){
  429. this.activeMax = max - this.scrollerHeight * 2 - this.el.getFrameWidth('tb') - Ext.num(this.el.shadowOffset, 0);
  430. this.ul.setHeight(this.activeMax);
  431. this.createScrollers();
  432. this.el.select('.x-menu-scroller').setDisplayed('');
  433. }else{
  434. this.ul.setHeight(full);
  435. this.el.select('.x-menu-scroller').setDisplayed('none');
  436. }
  437. this.ul.dom.scrollTop = 0;
  438. return returnY;
  439. },
  440. <span id='Ext-menu-Menu-method-createScrollers'> createScrollers : function(){
  441. </span> if(!this.scroller){
  442. this.scroller = {
  443. pos: 0,
  444. top: this.el.insertFirst({
  445. tag: 'div',
  446. cls: 'x-menu-scroller x-menu-scroller-top',
  447. html: '&amp;#160;'
  448. }),
  449. bottom: this.el.createChild({
  450. tag: 'div',
  451. cls: 'x-menu-scroller x-menu-scroller-bottom',
  452. html: '&amp;#160;'
  453. })
  454. };
  455. this.scroller.top.hover(this.onScrollerIn, this.onScrollerOut, this);
  456. this.scroller.topRepeater = new Ext.util.ClickRepeater(this.scroller.top, {
  457. listeners: {
  458. click: this.onScroll.createDelegate(this, [null, this.scroller.top], false)
  459. }
  460. });
  461. this.scroller.bottom.hover(this.onScrollerIn, this.onScrollerOut, this);
  462. this.scroller.bottomRepeater = new Ext.util.ClickRepeater(this.scroller.bottom, {
  463. listeners: {
  464. click: this.onScroll.createDelegate(this, [null, this.scroller.bottom], false)
  465. }
  466. });
  467. }
  468. },
  469. <span id='Ext-menu-Menu-method-onLayout'> onLayout : function(){
  470. </span> if(this.isVisible()){
  471. if(this.enableScrolling){
  472. this.constrainScroll(this.el.getTop());
  473. }
  474. if(this.floating){
  475. this.el.sync();
  476. }
  477. }
  478. },
  479. <span id='Ext-menu-Menu-method-focus'> focus : function(){
  480. </span> if(!this.hidden){
  481. this.doFocus.defer(50, this);
  482. }
  483. },
  484. <span id='Ext-menu-Menu-method-doFocus'> doFocus : function(){
  485. </span> if(!this.hidden){
  486. this.focusEl.focus();
  487. }
  488. },
  489. <span id='Ext-menu-Menu-method-hide'> /**
  490. </span> * Hides this menu and optionally all parent menus
  491. * @param {Boolean} deep (optional) True to hide all parent menus recursively, if any (defaults to false)
  492. */
  493. hide : function(deep){
  494. if (!this.isDestroyed) {
  495. this.deepHide = deep;
  496. Ext.menu.Menu.superclass.hide.call(this);
  497. delete this.deepHide;
  498. }
  499. },
  500. <span id='Ext-menu-Menu-method-onHide'> // private
  501. </span> onHide : function(){
  502. Ext.menu.Menu.superclass.onHide.call(this);
  503. this.deactivateActive();
  504. if(this.el &amp;&amp; this.floating){
  505. this.el.hide();
  506. }
  507. var pm = this.parentMenu;
  508. if(this.deepHide === true &amp;&amp; pm){
  509. if(pm.floating){
  510. pm.hide(true);
  511. }else{
  512. pm.deactivateActive();
  513. }
  514. }
  515. },
  516. <span id='Ext-menu-Menu-method-lookupComponent'> // private
  517. </span> lookupComponent : function(c){
  518. if(Ext.isString(c)){
  519. c = (c == 'separator' || c == '-') ? new Ext.menu.Separator() : new Ext.menu.TextItem(c);
  520. this.applyDefaults(c);
  521. }else{
  522. if(Ext.isObject(c)){
  523. c = this.getMenuItem(c);
  524. }else if(c.tagName || c.el){ // element. Wrap it.
  525. c = new Ext.BoxComponent({
  526. el: c
  527. });
  528. }
  529. }
  530. return c;
  531. },
  532. <span id='Ext-menu-Menu-method-applyDefaults'> applyDefaults : function(c) {
  533. </span> if (!Ext.isString(c)) {
  534. c = Ext.menu.Menu.superclass.applyDefaults.call(this, c);
  535. var d = this.internalDefaults;
  536. if(d){
  537. if(c.events){
  538. Ext.applyIf(c.initialConfig, d);
  539. Ext.apply(c, d);
  540. }else{
  541. Ext.applyIf(c, d);
  542. }
  543. }
  544. }
  545. return c;
  546. },
  547. <span id='Ext-menu-Menu-method-getMenuItem'> // private
  548. </span> getMenuItem : function(config) {
  549. config.ownerCt = this;
  550. if (!config.isXType) {
  551. if (!config.xtype &amp;&amp; Ext.isBoolean(config.checked)) {
  552. return new Ext.menu.CheckItem(config);
  553. }
  554. return Ext.create(config, this.defaultType);
  555. }
  556. return config;
  557. },
  558. <span id='Ext-menu-Menu-method-addSeparator'> /**
  559. </span> * Adds a separator bar to the menu
  560. * @return {Ext.menu.Item} The menu item that was added
  561. */
  562. addSeparator : function() {
  563. return this.add(new Ext.menu.Separator());
  564. },
  565. <span id='Ext-menu-Menu-method-addElement'> /**
  566. </span> * Adds an {@link Ext.Element} object to the menu
  567. * @param {Mixed} el The element or DOM node to add, or its id
  568. * @return {Ext.menu.Item} The menu item that was added
  569. */
  570. addElement : function(el) {
  571. return this.add(new Ext.menu.BaseItem({
  572. el: el
  573. }));
  574. },
  575. <span id='Ext-menu-Menu-method-addItem'> /**
  576. </span> * Adds an existing object based on {@link Ext.menu.BaseItem} to the menu
  577. * @param {Ext.menu.Item} item The menu item to add
  578. * @return {Ext.menu.Item} The menu item that was added
  579. */
  580. addItem : function(item) {
  581. return this.add(item);
  582. },
  583. <span id='Ext-menu-Menu-method-addMenuItem'> /**
  584. </span> * Creates a new {@link Ext.menu.Item} based an the supplied config object and adds it to the menu
  585. * @param {Object} config A MenuItem config object
  586. * @return {Ext.menu.Item} The menu item that was added
  587. */
  588. addMenuItem : function(config) {
  589. return this.add(this.getMenuItem(config));
  590. },
  591. <span id='Ext-menu-Menu-method-addText'> /**
  592. </span> * Creates a new {@link Ext.menu.TextItem} with the supplied text and adds it to the menu
  593. * @param {String} text The text to display in the menu item
  594. * @return {Ext.menu.Item} The menu item that was added
  595. */
  596. addText : function(text){
  597. return this.add(new Ext.menu.TextItem(text));
  598. },
  599. <span id='Ext-menu-Menu-method-onDestroy'> //private
  600. </span> onDestroy : function(){
  601. Ext.EventManager.removeResizeListener(this.hide, this);
  602. var pm = this.parentMenu;
  603. if(pm &amp;&amp; pm.activeChild == this){
  604. delete pm.activeChild;
  605. }
  606. delete this.parentMenu;
  607. Ext.menu.Menu.superclass.onDestroy.call(this);
  608. Ext.menu.MenuMgr.unregister(this);
  609. if(this.keyNav) {
  610. this.keyNav.disable();
  611. }
  612. var s = this.scroller;
  613. if(s){
  614. Ext.destroy(s.topRepeater, s.bottomRepeater, s.top, s.bottom);
  615. }
  616. Ext.destroy(
  617. this.el,
  618. this.focusEl,
  619. this.ul
  620. );
  621. }
  622. });
  623. Ext.reg('menu', Ext.menu.Menu);
  624. // MenuNav is a private utility class used internally by the Menu
  625. Ext.menu.MenuNav = Ext.extend(Ext.KeyNav, function(){
  626. function up(e, m){
  627. if(!m.tryActivate(m.items.indexOf(m.activeItem)-1, -1)){
  628. m.tryActivate(m.items.length-1, -1);
  629. }
  630. }
  631. function down(e, m){
  632. if(!m.tryActivate(m.items.indexOf(m.activeItem)+1, 1)){
  633. m.tryActivate(0, 1);
  634. }
  635. }
  636. return {
  637. constructor : function(menu){
  638. Ext.menu.MenuNav.superclass.constructor.call(this, menu.el);
  639. this.scope = this.menu = menu;
  640. },
  641. doRelay : function(e, h){
  642. var k = e.getKey();
  643. // Keystrokes within a form Field (e.g.: down in a Combo) do not navigate. Allow only TAB
  644. if (this.menu.activeItem &amp;&amp; this.menu.activeItem.isFormField &amp;&amp; k != e.TAB) {
  645. return false;
  646. }
  647. if(!this.menu.activeItem &amp;&amp; e.isNavKeyPress() &amp;&amp; k != e.SPACE &amp;&amp; k != e.RETURN){
  648. this.menu.tryActivate(0, 1);
  649. return false;
  650. }
  651. return h.call(this.scope || this, e, this.menu);
  652. },
  653. tab: function(e, m) {
  654. e.stopEvent();
  655. if (e.shiftKey) {
  656. up(e, m);
  657. } else {
  658. down(e, m);
  659. }
  660. },
  661. up : up,
  662. down : down,
  663. right : function(e, m){
  664. if(m.activeItem){
  665. m.activeItem.expandMenu(true);
  666. }
  667. },
  668. left : function(e, m){
  669. m.hide();
  670. if(m.parentMenu &amp;&amp; m.parentMenu.activeItem){
  671. m.parentMenu.activeItem.activate();
  672. }
  673. },
  674. enter : function(e, m){
  675. if(m.activeItem){
  676. e.stopPropagation();
  677. m.activeItem.onClick(e);
  678. m.fireEvent('click', this, m.activeItem);
  679. return true;
  680. }
  681. }
  682. };
  683. }());
  684. </pre>
  685. </body>
  686. </html>