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, {
29 * @cfg {Roo.menu.Menu} menu
34 * The text to show on the menu item.
38 * @cfg {String} html to render in menu
39 * The text to show on the menu item (HTML version).
44 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
48 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
50 itemCls : "x-menu-item",
52 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
56 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
63 ctype: "Roo.menu.Item",
66 onRender : function(container, position){
67 var el = document.createElement("a");
69 el.unselectable = "on";
70 el.href = this.href || "#";
72 el.target = this.hrefTarget;
74 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
76 var html = this.html.length ? this.html : String.format('{0}',this.text);
78 el.innerHTML = String.format(
79 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
80 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
82 Roo.menu.Item.superclass.onRender.call(this, container, position);
86 * Sets the text to display in this menu item
87 * @param {String} text The text to display
88 * @param {Boolean} isHTML true to indicate text is pure html.
90 setText : function(text, isHTML){
98 var html = this.html.length ? this.html : String.format('{0}',this.text);
100 this.el.update(String.format(
101 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
102 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
103 this.parentMenu.autoWidth();
108 handleClick : function(e){
109 if(!this.href){ // if no link defined, stop the event automatically
112 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
116 activate : function(autoExpand){
117 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
127 shouldDeactivate : function(e){
128 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
129 if(this.menu && this.menu.isVisible()){
130 return !this.menu.getEl().getRegion().contains(e.getPoint());
138 deactivate : function(){
139 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
144 expandMenu : function(autoActivate){
145 if(!this.disabled && this.menu){
146 clearTimeout(this.hideTimer);
147 delete this.hideTimer;
148 if(!this.menu.isVisible() && !this.showTimer){
149 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
150 }else if (this.menu.isVisible() && autoActivate){
151 this.menu.tryActivate(0, 1);
157 deferExpand : function(autoActivate){
158 delete this.showTimer;
159 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
161 this.menu.tryActivate(0, 1);
166 hideMenu : function(){
167 clearTimeout(this.showTimer);
168 delete this.showTimer;
169 if(!this.hideTimer && this.menu && this.menu.isVisible()){
170 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
175 deferHide : function(){
176 delete this.hideTimer;