Roo.menu.Item = function(config){
Roo.menu.Item.superclass.constructor.call(this, config);
if(this.menu){
this.menu = Roo.menu.MenuMgr.get(this.menu);
}
};
Roo.extend(Roo.menu.Item, Roo.menu.BaseItem, {
text: '',
html: '',
icon: undefined,
itemCls : "x-menu-item",
canActivate : true,
showDelay: 200,
hideDelay: 200,
ctype: "Roo.menu.Item",
onRender : function(container, position){
var el = document.createElement("a");
el.hideFocus = true;
el.unselectable = "on";
el.href = this.href || "#";
if(this.hrefTarget){
el.target = this.hrefTarget;
}
el.className = this.itemCls + (this.menu ? " x-menu-item-arrow" : "") + (this.cls ? " " + this.cls : "");
var html = this.html.length ? this.html : String.format('{0}',this.text);
el.innerHTML = String.format(
'<img src="{0}" class="x-menu-item-icon {1}" />' + html,
this.icon || Roo.BLANK_IMAGE_URL, this.iconCls || '');
this.el = el;
Roo.menu.Item.superclass.onRender.call(this, container, position);
},
setText : function(text, isHTML){
if (isHTML) {
this.html = text;
} else {
this.text = text;
this.html = '';
}
if(this.rendered){
var html = this.html.length ? this.html : String.format('{0}',this.text);
this.el.update(String.format(
'<img src="{0}" class="x-menu-item-icon {2}">' + html,
this.icon || Roo.BLANK_IMAGE_URL, this.text, this.iconCls || ''));
this.parentMenu.autoWidth();
}
},
handleClick : function(e){
if(!this.href){ e.stopEvent();
}
Roo.menu.Item.superclass.handleClick.apply(this, arguments);
},
activate : function(autoExpand){
if(Roo.menu.Item.superclass.activate.apply(this, arguments)){
this.focus();
if(autoExpand){
this.expandMenu();
}
}
return true;
},
shouldDeactivate : function(e){
if(Roo.menu.Item.superclass.shouldDeactivate.call(this, e)){
if(this.menu && this.menu.isVisible()){
return !this.menu.getEl().getRegion().contains(e.getPoint());
}
return true;
}
return false;
},
deactivate : function(){
Roo.menu.Item.superclass.deactivate.apply(this, arguments);
this.hideMenu();
},
expandMenu : function(autoActivate){
if(!this.disabled && this.menu){
clearTimeout(this.hideTimer);
delete this.hideTimer;
if(!this.menu.isVisible() && !this.showTimer){
this.showTimer = this.deferExpand.defer(this.showDelay, this, [autoActivate]);
}else if (this.menu.isVisible() && autoActivate){
this.menu.tryActivate(0, 1);
}
}
},
deferExpand : function(autoActivate){
delete this.showTimer;
this.menu.show(this.container, this.parentMenu.subMenuAlign || "tl-tr?", this.parentMenu);
if(autoActivate){
this.menu.tryActivate(0, 1);
}
},
hideMenu : function(){
clearTimeout(this.showTimer);
delete this.showTimer;
if(!this.hideTimer && this.menu && this.menu.isVisible()){
this.hideTimer = this.deferHide.defer(this.hideDelay, this);
}
},
deferHide : function(){
delete this.hideTimer;
this.menu.hide();
}
});