PDA

View Full Version : Closing a tab shows a hidden panel



mscifo
8 Nov 2006, 11:14 AM
Jack

I've created three panels and hidden the second and third one, show only the first tab/panel shows. I am using your code to dynamically create a new tab. Once a new tab is created, 2 tabs show up, the first panel and the new panel. However, when I close the newly created tab, instead of activating the first tab/panel, the 3rd hidden panel shows up. What should happen is when you close a tab then only visible panels should be shown. Better yet, it would be great if the tab code kept track of your tab selections so when a tab is closed, the previously selected tab is selected.

-Matt

jack.slocum
8 Nov 2006, 5:01 PM
I've fixed this and it will be in the next release.

I also separated the logic for selecting the next tab into it's own function that you can override to implement another kind of tab selection.

Jack

jack.slocum
8 Nov 2006, 5:05 PM
Here's a patch for you.


YAHOO.ext.TabPanel.prototype.removeTab = function(id){
var items = this.items;
var tab = items[id];
if(!tab) return;
var index = items.indexOf(tab);
if(this.active == tab && items.length > 1){
var newTab = this.getNextAvailable(index);
if(newTab)newTab.activate();
}
this.stripEl.dom.removeChild(tab.pnode.dom);
this.bodyEl.dom.removeChild(tab.bodyEl.dom);
items.splice(index, 1);
delete items[tab.id];
this.autoSizeTabs();
};

YAHOO.ext.TabPanel.prototype.getNextAvailable = function(start){
var items = this.items;
var index = start;
// look for a next tab that will slide over to
// replace the one being removed
while(index < items.length){
var item = items[++index];
if(item && !item.isHidden()){
return item;
}
}
// if one isn't found select the previous tab (on the left)
var index = start;
while(index >= 0){
var item = items[--index];
if(item && !item.isHidden()){
return item;
}
}
return null;
};