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.

251 lines
9.8 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-Item-method-constructor'><span id='Ext-menu-Item'>/**
  19. </span></span> * @class Ext.menu.Item
  20. * @extends Ext.menu.BaseItem
  21. * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
  22. * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific
  23. * activation and click handling.
  24. * @constructor
  25. * Creates a new Item
  26. * @param {Object} config Configuration options
  27. * @xtype menuitem
  28. */
  29. Ext.menu.Item = Ext.extend(Ext.menu.BaseItem, {
  30. <span id='Ext-menu-Item-property-menu'> /**
  31. </span> * @property menu
  32. * @type Ext.menu.Menu
  33. * The submenu associated with this Item if one was configured.
  34. */
  35. <span id='Ext-menu-Item-cfg-menu'> /**
  36. </span> * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an
  37. * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.
  38. */
  39. <span id='Ext-menu-Item-cfg-icon'> /**
  40. </span> * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If
  41. * icon is specified {@link #iconCls} should not be.
  42. */
  43. <span id='Ext-menu-Item-cfg-iconCls'> /**
  44. </span> * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for
  45. * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.
  46. */
  47. <span id='Ext-menu-Item-cfg-text'> /**
  48. </span> * @cfg {String} text The text to display in this item (defaults to '').
  49. */
  50. <span id='Ext-menu-Item-cfg-href'> /**
  51. </span> * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').
  52. */
  53. <span id='Ext-menu-Item-cfg-hrefTarget'> /**
  54. </span> * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').
  55. */
  56. <span id='Ext-menu-Item-cfg-itemCls'> /**
  57. </span> * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')
  58. */
  59. itemCls : 'x-menu-item',
  60. <span id='Ext-menu-Item-cfg-canActivate'> /**
  61. </span> * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
  62. */
  63. canActivate : true,
  64. <span id='Ext-menu-Item-cfg-showDelay'> /**
  65. </span> * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
  66. */
  67. showDelay: 200,
  68. <span id='Ext-menu-Item-cfg-altText'> /**
  69. </span> * @cfg {String} altText The altText to use for the icon, if it exists. Defaults to &lt;tt&gt;''&lt;/tt&gt;.
  70. */
  71. altText: '',
  72. <span id='Ext-menu-Item-property-hideDelay'> // doc'd in BaseItem
  73. </span> hideDelay: 200,
  74. <span id='Ext-menu-Item-property-ctype'> // private
  75. </span> ctype: 'Ext.menu.Item',
  76. <span id='Ext-menu-Item-method-initComponent'> initComponent : function(){
  77. </span> Ext.menu.Item.superclass.initComponent.call(this);
  78. if(this.menu){
  79. // If array of items, turn it into an object config so we
  80. // can set the ownerCt property in the config
  81. if (Ext.isArray(this.menu)){
  82. this.menu = { items: this.menu };
  83. }
  84. // An object config will work here, but an instance of a menu
  85. // will have already setup its ref's and have no effect
  86. if (Ext.isObject(this.menu)){
  87. this.menu.ownerCt = this;
  88. }
  89. this.menu = Ext.menu.MenuMgr.get(this.menu);
  90. this.menu.ownerCt = undefined;
  91. }
  92. },
  93. <span id='Ext-menu-Item-method-onRender'> // private
  94. </span> onRender : function(container, position){
  95. if (!this.itemTpl) {
  96. this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(
  97. '&lt;a id=&quot;{id}&quot; class=&quot;{cls} x-unselectable&quot; hidefocus=&quot;true&quot; unselectable=&quot;on&quot; href=&quot;{href}&quot;',
  98. '&lt;tpl if=&quot;hrefTarget&quot;&gt;',
  99. ' target=&quot;{hrefTarget}&quot;',
  100. '&lt;/tpl&gt;',
  101. '&gt;',
  102. '&lt;img alt=&quot;{altText}&quot; src=&quot;{icon}&quot; class=&quot;x-menu-item-icon {iconCls}&quot;/&gt;',
  103. '&lt;span class=&quot;x-menu-item-text&quot;&gt;{text}&lt;/span&gt;',
  104. '&lt;/a&gt;'
  105. );
  106. }
  107. var a = this.getTemplateArgs();
  108. this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);
  109. this.iconEl = this.el.child('img.x-menu-item-icon');
  110. this.textEl = this.el.child('.x-menu-item-text');
  111. if(!this.href) { // if no link defined, prevent the default anchor event
  112. this.mon(this.el, 'click', Ext.emptyFn, null, { preventDefault: true });
  113. }
  114. Ext.menu.Item.superclass.onRender.call(this, container, position);
  115. },
  116. <span id='Ext-menu-Item-method-getTemplateArgs'> getTemplateArgs: function() {
  117. </span> return {
  118. id: this.id,
  119. cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),
  120. href: this.href || '#',
  121. hrefTarget: this.hrefTarget,
  122. icon: this.icon || Ext.BLANK_IMAGE_URL,
  123. iconCls: this.iconCls || '',
  124. text: this.itemText||this.text||'&amp;#160;',
  125. altText: this.altText || ''
  126. };
  127. },
  128. <span id='Ext-menu-Item-method-setText'> /**
  129. </span> * Sets the text to display in this menu item
  130. * @param {String} text The text to display
  131. */
  132. setText : function(text){
  133. this.text = text||'&amp;#160;';
  134. if(this.rendered){
  135. this.textEl.update(this.text);
  136. this.parentMenu.layout.doAutoSize();
  137. }
  138. },
  139. <span id='Ext-menu-Item-method-setIconClass'> /**
  140. </span> * Sets the CSS class to apply to the item's icon element
  141. * @param {String} cls The CSS class to apply
  142. */
  143. setIconClass : function(cls){
  144. var oldCls = this.iconCls;
  145. this.iconCls = cls;
  146. if(this.rendered){
  147. this.iconEl.replaceClass(oldCls, this.iconCls);
  148. }
  149. },
  150. <span id='Ext-menu-Item-method-beforeDestroy'> //private
  151. </span> beforeDestroy: function(){
  152. clearTimeout(this.showTimer);
  153. clearTimeout(this.hideTimer);
  154. if (this.menu){
  155. delete this.menu.ownerCt;
  156. this.menu.destroy();
  157. }
  158. Ext.menu.Item.superclass.beforeDestroy.call(this);
  159. },
  160. <span id='Ext-menu-Item-method-handleClick'> // private
  161. </span> handleClick : function(e){
  162. if(!this.href){ // if no link defined, stop the event automatically
  163. e.stopEvent();
  164. }
  165. Ext.menu.Item.superclass.handleClick.apply(this, arguments);
  166. },
  167. <span id='Ext-menu-Item-method-activate'> // private
  168. </span> activate : function(autoExpand){
  169. if(Ext.menu.Item.superclass.activate.apply(this, arguments)){
  170. this.focus();
  171. if(autoExpand){
  172. this.expandMenu();
  173. }
  174. }
  175. return true;
  176. },
  177. <span id='Ext-menu-Item-method-shouldDeactivate'> // private
  178. </span> shouldDeactivate : function(e){
  179. if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){
  180. if(this.menu &amp;&amp; this.menu.isVisible()){
  181. return !this.menu.getEl().getRegion().contains(e.getPoint());
  182. }
  183. return true;
  184. }
  185. return false;
  186. },
  187. <span id='Ext-menu-Item-method-deactivate'> // private
  188. </span> deactivate : function(){
  189. Ext.menu.Item.superclass.deactivate.apply(this, arguments);
  190. this.hideMenu();
  191. },
  192. <span id='Ext-menu-Item-method-expandMenu'> // private
  193. </span> expandMenu : function(autoActivate){
  194. if(!this.disabled &amp;&amp; this.menu){
  195. clearTimeout(this.hideTimer);
  196. delete this.hideTimer;
  197. if(!this.menu.isVisible() &amp;&amp; !this.showTimer){
  198. this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
  199. }else if (this.menu.isVisible() &amp;&amp; autoActivate){
  200. this.menu.tryActivate(0, 1);
  201. }
  202. }
  203. },
  204. <span id='Ext-menu-Item-method-deferExpand'> // private
  205. </span> deferExpand : function(autoActivate){
  206. delete this.showTimer;
  207. this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);
  208. if(autoActivate){
  209. this.menu.tryActivate(0, 1);
  210. }
  211. },
  212. <span id='Ext-menu-Item-method-hideMenu'> // private
  213. </span> hideMenu : function(){
  214. clearTimeout(this.showTimer);
  215. delete this.showTimer;
  216. if(!this.hideTimer &amp;&amp; this.menu &amp;&amp; this.menu.isVisible()){
  217. this.hideTimer = this.deferHide.defer(this.hideDelay, this);
  218. }
  219. },
  220. <span id='Ext-menu-Item-method-deferHide'> // private
  221. </span> deferHide : function(){
  222. delete this.hideTimer;
  223. if(this.menu.over){
  224. this.parentMenu.setActiveItem(this, false);
  225. }else{
  226. this.menu.hide();
  227. }
  228. }
  229. });
  230. Ext.reg('menuitem', Ext.menu.Item);</pre>
  231. </body>
  232. </html>