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, {
31 * The text to show on the menu item.
36 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
40 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
42 itemCls : "x-menu-item",
44 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
48 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
55 ctype: "Roo.menu.Item",
58 onRender : function(container, position){
59 var el = document.createElement("a");
61 el.unselectable = "on";
62 el.href = this.href || "#";
64 el.target = this.hrefTarget;
66 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
67 el.innerHTML = String.format(
68 '<img src="{0}" class="x-menu-item-icon {2}" />{1}',
69 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || '');
71 Roo.menu.Item.superclass.onRender.call(this, container, position);
75 * Sets the text to display in this menu item
76 * @param {String} text The text to display
78 setText : function(text){
81 this.el.update(String.format(
82 '<img src="{0}" class="x-menu-item-icon {2}">{1}',
83 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
84 this.parentMenu.autoWidth();
89 handleClick : function(e){
90 if(!this.href){ // if no link defined, stop the event automatically
93 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
97 activate : function(autoExpand){
98 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
108 shouldDeactivate : function(e){
109 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
110 if(this.menu && this.menu.isVisible()){
111 return !this.menu.getEl().getRegion().contains(e.getPoint());
119 deactivate : function(){
120 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
125 expandMenu : function(autoActivate){
126 if(!this.disabled && this.menu){
127 clearTimeout(this.hideTimer);
128 delete this.hideTimer;
129 if(!this.menu.isVisible() && !this.showTimer){
130 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
131 }else if (this.menu.isVisible() && autoActivate){
132 this.menu.tryActivate(0, 1);
138 deferExpand : function(autoActivate){
139 delete this.showTimer;
140 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
142 this.menu.tryActivate(0, 1);
147 hideMenu : function(){
148 clearTimeout(this.showTimer);
149 delete this.showTimer;
150 if(!this.hideTimer && this.menu && this.menu.isVisible()){
151 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
156 deferHide : function(){
157 delete this.hideTimer;