4 * Copyright(c) 2006-2007, Ext JS, LLC.
6 * Originally Released Under LGPL - original licence link has changed is not relivant.
9 * <script type="text/javascript">
12 * @class Roo.menu.Item
13 * @extends Roo.menu.BaseItem
14 * A base class for all menu items that require menu-related functionality (like sub-menus) and are not static
15 * display items. Item extends the base functionality of {@link Roo.menu.BaseItem} by adding menu-specific
16 * activation and click handling.
19 * @param {Object} config Configuration options
21 Roo.menu.Item = function(config){
22 Roo.menu.Item.superclass.constructor.call(this, config);
24 this.menu = Roo.menu.MenuMgr.get(this.menu);
27 Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
30 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
33 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
35 itemCls : "x-menu-item",
37 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
41 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
48 ctype: "Roo.menu.Item",
51 onRender : function(container, position){
52 var el = document.createElement("a");
54 el.unselectable = "on";
55 el.href = this.href || "#";
57 el.target = this.hrefTarget;
59 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
60 el.innerHTML = String.format(
61 '<img src="{0}" class="x-menu-item-icon {2}" />{1}',
62 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || '');
64 Roo.menu.Item.superclass.onRender.call(this, container, position);
68 * Sets the text to display in this menu item
69 * @param {String} text The text to display
71 setText : function(text){
74 this.el.update(String.format(
75 '<img src="{0}" class="x-menu-item-icon {2}">{1}',
76 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
77 this.parentMenu.autoWidth();
82 handleClick : function(e){
83 if(!this.href){ // if no link defined, stop the event automatically
86 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
90 activate : function(autoExpand){
91 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
101 shouldDeactivate : function(e){
102 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
103 if(this.menu && this.menu.isVisible()){
104 return !this.menu.getEl().getRegion().contains(e.getPoint());
112 deactivate : function(){
113 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
118 expandMenu : function(autoActivate){
119 if(!this.disabled && this.menu){
120 clearTimeout(this.hideTimer);
121 delete this.hideTimer;
122 if(!this.menu.isVisible() && !this.showTimer){
123 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
124 }else if (this.menu.isVisible() && autoActivate){
125 this.menu.tryActivate(0, 1);
131 deferExpand : function(autoActivate){
132 delete this.showTimer;
133 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
135 this.menu.tryActivate(0, 1);
140 hideMenu : function(){
141 clearTimeout(this.showTimer);
142 delete this.showTimer;
143 if(!this.hideTimer && this.menu && this.menu.isVisible()){
144 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
149 deferHide : function(){
150 delete this.hideTimer;