Code:
//You cannot attach mouse events directly to a TabPanel. They must instead be attached to the underlying strip component.
//Since this is a private object, an override must be used to expose it.
Ext.override(Ext.TabPanel, {
getStrip: function() {
return this.strip;
}
});
Ext.onReady(function(){
// The tab panel
var tabs = new Ext.TabPanel({
renderTo: document.body,
activeTab: 0,
width:600,
height:250,
frame: true,
items: [
{
title: "Tab 2",
html: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus.<br/><br/> Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.",
menu: new Ext.menu.Menu({
items: [
{text: "Menu Item 1"},
{text: "Menu Item 2"},
{text: "Menu Item 3"}
],
listeners: {
itemclick: function(baseItem, e) {
var tab = baseItem.parentMenu.parentTab;
//do stuff here
//Hide menu and make this the active tab
this.hide();
tab.ownerCt.setActiveTab(tab);
}
}
})
},{
title: "Tab 2",
html: "Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Sed metus nibh, sodales a, porta at, vulputate eget, dui. Pellentesque ut nisl. Maecenas tortor turpis, interdum non, sodales non, iaculis ac, lacus.<br/><br/> Vestibulum auctor, tortor quis iaculis malesuada, libero lectus bibendum purus, sit amet tincidunt quam turpis vel lacus. In pellentesque nisl non sem. Suspendisse nunc sem, pretium eget, cursus a, fringilla vel, urna.",
menu: new Ext.menu.Menu({
items: [
{text: "Menu Item 1"},
{text: "Menu Item 2"},
{text: "Menu Item 3"}
],
listeners: {
itemclick: function(baseItem, e) {
var tab = baseItem.parentMenu.parentTab;
//do stuff here
//Hide menu and make this the active tab
this.hide();
tab.ownerCt.setActiveTab(tab);
}
}
})
}
],
listeners: {
render: function(){
//retrieve the underlying strip component and attach the mouseover event to that
var strip = this.getStrip();
strip.on({
"mouseover": function(e, t){
//Hide any menus that may be on the screen
Ext.menu.MenuMgr.hideAll();
//Determine which tab the mouse is currently over
var tab = tabs.findTargets(e);
//Only pop the menu up if this isnt the current tab and the tab has a menu
if (!tab.close && tab.item && tab.item != tabs.activeTab && tab.item.menu && !tab.item.menu.isVisible()) {
//Get the tab measurements
var rect = tab.el.getBoundingClientRect();
//force the menu association to the tab here since there is scope issues in the definition
//im sure there is a better way to do this...
tab.item.menu.parentTab = tab.item;
//Display the menu directly below the tab
tab.item.menu.showAt([rect.left, rect.bottom]);
}
}
});
}
}
});
});