PDA

View Full Version : TabScrollerMenu tweaks



Buzzwords
25 Nov 2011, 6:25 AM
A couple of small things popped up on this nice little plugin. First, when the tabpanel has fewer tabs than the value specified for menu pageSize, no menu is built at all. The plugin code tries to avoid adding the active tab AND any hidden tabpanel children to the menu. I think the assumption was that all tabs would be visible in this case. But if the tabpanel is in a window or another pane whose width is such that some tabs are hidden, it would be helpful to have all tabs in the dropdown menu. To change the default behavior I changed function generateTabMenuItems (around line ~200) from this:

else {
tabPanel.items.each(function(item) {
if (item.id != curActive.id && !item.hidden) {
me.tabsMenu.add(me.autoGenMenuItem(item));
}
});
}


to this:


else {
tabPanel.items.each(function(item) {
me.tabsMenu.add(me.autoGenMenuItem(item));
});
}

In addition, I found an edge case bug. It is unlikely to be seen by most, but I'm including this description just in case. I was working with some mock data that had an 'id' field in each row, and the values of 'id' were integers starting with one (1). I used this data to build a set of tabs, assigning each tab the id of the record's 'id'. Doing this caused the first value in the tabscrollermenu to be duplicated. The reason is that the use of tabPanel.items.get sees a record having an id value of '1', which is actually the first record and was already added to the tree under index 0. This behavior is avoided by directly referencing the items.items array within the tabpanel. This change is at line 168.


for (x = 0; x < pageSize; x++) {
index = x + curPage - pageSize;

//item = tabPanel.items.get(index);
item = tabPanel.items.items[index];

menuItems.push(me.autoGenMenuItem(item));
}

mitchellsimoens
25 Nov 2011, 6:59 AM
Nice job!