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.
35 * @cfg {String} HTML to render in menu
36 * The text to show on the menu item (HTML version).
41 * The path to an icon to display in this menu item (defaults to Roo.BLANK_IMAGE_URL)
45 * @cfg {String} itemCls The default CSS class to use for menu items (defaults to "x-menu-item")
47 itemCls : "x-menu-item",
49 * @cfg {Boolean} canActivate True if this item can be visually activated (defaults to true)
53 * @cfg {Number} showDelay Length of time in milliseconds to wait before showing this item (defaults to 200)
60 ctype: "Roo.menu.Item",
63 onRender : function(container, position){
64 var el = document.createElement("a");
66 el.unselectable = "on";
67 el.href = this.href || "#";
69 el.target = this.hrefTarget;
71 el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
73 var html = this.html.length ? this.html : String.format('{0}',this.text);
75 el.innerHTML = String.format(
76 '<img src="{0}" class="x-menu-item-icon {1}" />' + html,
77 this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
79 Roo.menu.Item.superclass.onRender.call(this, container, position);
83 * Sets the text to display in this menu item
84 * @param {String} text The text to display
85 * @param {Boolean} isHTML true to indicate text is pure html.
87 setText : function(text, isHTML){
95 var html = this.html.length ? this.html : String.format('{0}',this.text);
97 this.el.update(String.format(
98 '<img src="{0}" class="x-menu-item-icon {2}">' + html,
99 this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
100 this.parentMenu.autoWidth();
105 handleClick : function(e){
106 if(!this.href){ // if no link defined, stop the event automatically
109 Roo.menu.Item.superclass.handleClick.apply(this, arguments);
113 activate : function(autoExpand){
114 if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
124 shouldDeactivate : function(e){
125 if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
126 if(this.menu && this.menu.isVisible()){
127 return !this.menu.getEl().getRegion().contains(e.getPoint());
135 deactivate : function(){
136 Roo.menu.Item.superclass.deactivate.apply(this, arguments);
141 expandMenu : function(autoActivate){
142 if(!this.disabled && this.menu){
143 clearTimeout(this.hideTimer);
144 delete this.hideTimer;
145 if(!this.menu.isVisible() && !this.showTimer){
146 this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
147 }else if (this.menu.isVisible() && autoActivate){
148 this.menu.tryActivate(0, 1);
154 deferExpand : function(autoActivate){
155 delete this.showTimer;
156 this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
158 this.menu.tryActivate(0, 1);
163 hideMenu : function(){
164 clearTimeout(this.showTimer);
165 delete this.showTimer;
166 if(!this.hideTimer && this.menu && this.menu.isVisible()){
167 this.hideTimer = this.deferHide.defer(this.hideDelay, this);
172 deferHide : function(){
173 delete this.hideTimer;