+++ /dev/null
-/*!
- * Ext JS Library 3.1.1
- * Copyright(c) 2006-2010 Ext JS, LLC
- * licensing@extjs.com
- * http://www.extjs.com/license
- */
-/**\r
- * @class Ext.menu.Item\r
- * @extends Ext.menu.BaseItem\r
- * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static\r
- * display items. Item extends the base functionality of {@link Ext.menu.BaseItem} by adding menu-specific\r
- * activation and click handling.\r
- * @constructor\r
- * Creates a new Item\r
- * @param {Object} config Configuration options\r
- * @xtype menuitem\r
- */\r
-Ext.menu.Item = Ext.extend(Ext.menu.BaseItem, {\r
- /**\r
- * @property menu\r
- * @type Ext.menu.Menu\r
- * The submenu associated with this Item if one was configured.\r
- */\r
- /**\r
- * @cfg {Mixed} menu (optional) Either an instance of {@link Ext.menu.Menu} or the config object for an\r
- * {@link Ext.menu.Menu} which acts as the submenu when this item is activated.\r
- */\r
- /**\r
- * @cfg {String} icon The path to an icon to display in this item (defaults to Ext.BLANK_IMAGE_URL). If\r
- * icon is specified {@link #iconCls} should not be.\r
- */\r
- /**\r
- * @cfg {String} iconCls A CSS class that specifies a background image that will be used as the icon for\r
- * this item (defaults to ''). If iconCls is specified {@link #icon} should not be.\r
- */\r
- /**\r
- * @cfg {String} text The text to display in this item (defaults to '').\r
- */\r
- /**\r
- * @cfg {String} href The href attribute to use for the underlying anchor link (defaults to '#').\r
- */\r
- /**\r
- * @cfg {String} hrefTarget The target attribute to use for the underlying anchor link (defaults to '').\r
- */\r
- /**\r
- * @cfg {String} itemCls The default CSS class to use for menu items (defaults to 'x-menu-item')\r
- */\r
- itemCls : 'x-menu-item',\r
- /**\r
- * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)\r
- */\r
- canActivate : true,\r
- /**\r
- * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)\r
- */\r
- showDelay: 200,\r
- // doc'd in BaseItem\r
- hideDelay: 200,\r
-\r
- // private\r
- ctype: 'Ext.menu.Item',\r
-\r
- initComponent : function(){\r
- Ext.menu.Item.superclass.initComponent.call(this);\r
- if(this.menu){\r
- this.menu = Ext.menu.MenuMgr.get(this.menu);\r
- this.menu.ownerCt = this;\r
- }\r
- },\r
-\r
- // private\r
- onRender : function(container, position){\r
- if (!this.itemTpl) {\r
- this.itemTpl = Ext.menu.Item.prototype.itemTpl = new Ext.XTemplate(\r
- '<a id="{id}" class="{cls}" hidefocus="true" unselectable="on" href="{href}"',\r
- '<tpl if="hrefTarget">',\r
- ' target="{hrefTarget}"',\r
- '</tpl>',\r
- '>',\r
- '<img src="{icon}" class="x-menu-item-icon {iconCls}"/>',\r
- '<span class="x-menu-item-text">{text}</span>',\r
- '</a>'\r
- );\r
- }\r
- var a = this.getTemplateArgs();\r
- this.el = position ? this.itemTpl.insertBefore(position, a, true) : this.itemTpl.append(container, a, true);\r
- this.iconEl = this.el.child('img.x-menu-item-icon');\r
- this.textEl = this.el.child('.x-menu-item-text');\r
- if(!this.href) { // if no link defined, prevent the default anchor event\r
- this.mon(this.el, 'click', Ext.emptyFn, null, { preventDefault: true });\r
- }\r
- Ext.menu.Item.superclass.onRender.call(this, container, position);\r
- },\r
-\r
- getTemplateArgs: function() {\r
- return {\r
- id: this.id,\r
- cls: this.itemCls + (this.menu ? ' x-menu-item-arrow' : '') + (this.cls ? ' ' + this.cls : ''),\r
- href: this.href || '#',\r
- hrefTarget: this.hrefTarget,\r
- icon: this.icon || Ext.BLANK_IMAGE_URL,\r
- iconCls: this.iconCls || '',\r
- text: this.itemText||this.text||' '\r
- };\r
- },\r
-\r
- /**\r
- * Sets the text to display in this menu item\r
- * @param {String} text The text to display\r
- */\r
- setText : function(text){\r
- this.text = text||' ';\r
- if(this.rendered){\r
- this.textEl.update(this.text);\r
- this.parentMenu.layout.doAutoSize();\r
- }\r
- },\r
-\r
- /**\r
- * Sets the CSS class to apply to the item's icon element\r
- * @param {String} cls The CSS class to apply\r
- */\r
- setIconClass : function(cls){\r
- var oldCls = this.iconCls;\r
- this.iconCls = cls;\r
- if(this.rendered){\r
- this.iconEl.replaceClass(oldCls, this.iconCls);\r
- }\r
- },\r
-\r
- //private\r
- beforeDestroy: function(){\r
- if (this.menu){\r
- delete this.menu.ownerCt;\r
- this.menu.destroy();\r
- }\r
- Ext.menu.Item.superclass.beforeDestroy.call(this);\r
- },\r
-\r
- // private\r
- handleClick : function(e){\r
- if(!this.href){ // if no link defined, stop the event automatically\r
- e.stopEvent();\r
- }\r
- Ext.menu.Item.superclass.handleClick.apply(this, arguments);\r
- },\r
-\r
- // private\r
- activate : function(autoExpand){\r
- if(Ext.menu.Item.superclass.activate.apply(this, arguments)){\r
- this.focus();\r
- if(autoExpand){\r
- this.expandMenu();\r
- }\r
- }\r
- return true;\r
- },\r
-\r
- // private\r
- shouldDeactivate : function(e){\r
- if(Ext.menu.Item.superclass.shouldDeactivate.call(this, e)){\r
- if(this.menu && this.menu.isVisible()){\r
- return !this.menu.getEl().getRegion().contains(e.getPoint());\r
- }\r
- return true;\r
- }\r
- return false;\r
- },\r
-\r
- // private\r
- deactivate : function(){\r
- Ext.menu.Item.superclass.deactivate.apply(this, arguments);\r
- this.hideMenu();\r
- },\r
-\r
- // private\r
- expandMenu : function(autoActivate){\r
- if(!this.disabled && this.menu){\r
- clearTimeout(this.hideTimer);\r
- delete this.hideTimer;\r
- if(!this.menu.isVisible() && !this.showTimer){\r
- this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);\r
- }else if (this.menu.isVisible() && autoActivate){\r
- this.menu.tryActivate(0, 1);\r
- }\r
- }\r
- },\r
-\r
- // private\r
- deferExpand : function(autoActivate){\r
- delete this.showTimer;\r
- this.menu.show(this.container, this.parentMenu.subMenuAlign || 'tl-tr?', this.parentMenu);\r
- if(autoActivate){\r
- this.menu.tryActivate(0, 1);\r
- }\r
- },\r
-\r
- // private\r
- hideMenu : function(){\r
- clearTimeout(this.showTimer);\r
- delete this.showTimer;\r
- if(!this.hideTimer && this.menu && this.menu.isVisible()){\r
- this.hideTimer = this.deferHide.defer(this.hideDelay, this);\r
- }\r
- },\r
-\r
- // private\r
- deferHide : function(){\r
- delete this.hideTimer;\r
- if(this.menu.over){\r
- this.parentMenu.setActiveItem(this, false);\r
- }else{\r
- this.menu.hide();\r
- }\r
- }\r
-});\r
-Ext.reg('menuitem', Ext.menu.Item);
\ No newline at end of file