Bottom and top Spry tabbed panels on one page
I posted a while back about how to create a Spry tabbed panel with the tabs at the bottom of the panel. The changes I suggested will cause other tabbed panels to be broken. I should have warned about that happening in that post, and suggested a different way that allows bottoms and tops to co-exist peacefully. Someone ran into the issue when they wanted to have top and bottom tabs on the same page. Here is what should work to allow both:
1). Add the following code to the head of your document. The styles and functions will be used to make sure that the bottom tabs look and work properly.
<style type="text/css">
<!--
.TabbedPanelsBottomTab {
position: relative;
top: -1px;
float: left;
padding: 4px 10px;
margin: 0px 1px 0px 0px;
font: bold 0.7em sans-serif;
background-color: #DDD;
list-style: none;
border-left: solid 1px #CCC;
border-bottom: solid 1px #999;
border-top: solid 1px #999;
border-right: solid 1px #999;
-moz-user-select: none;
-khtml-user-select: none;
cursor: pointer;
}
.TabbedPanelsBottomTabSelected {
background-color: #EEE;
border-top: 1px solid #EEE;
}
-->
</style>
<script type="text/javascript">
<!--
var getBottomTabGroup = function()
{
if (this.element)
{
var children = this.getElementChildren(this.element);
if (children.length)
return children[1];
}
return null;
};
var getBottomContentPanelGroup = function()
{
if (this.element)
{
var children = this.getElementChildren(this.element);
if (children.length > 1)
return children[0];
}
return null;
};
-->
</script>
2). Next modify your bottom tabs to look similar to the following code. Note that the main changes from a top tab is that the tabs UL is at the bottom, and that the LIs now have a class of "TabbedPanelsBottomTab" (defined in the STYLE block above):
<div id="TabbedPanels2" class="TabbedPanels">
<div class="TabbedPanelsContentGroup">
<div class="TabbedPanelsContent">Content 1</div>
<div class="TabbedPanelsContent">Content 2</div>
</div>
<ul class="TabbedPanelsTabGroup">
<li class="TabbedPanelsBottomTab" tabindex="0">Tab 1</li>
<li class="TabbedPanelsBottomTab" tabindex="0">Tab 2</li>
</ul>
</div>
3). Next, in the constructor for the bottom tabbed panel, change it to (all one line of code if you like):
var TabbedPanels2 = new Spry.Widget.TabbedPanels("TabbedPanels2",
{
tabSelectedClass:"TabbedPanelsBottomTabSelected",
getTabGroup : getBottomTabGroup,
getContentPanelGroup: getBottomContentPanelGroup
}
);
The options being passed in tell the bottom tabbed panel to use the "TabbedPanelsBottomTabSelected" CSS class as the class when a tab is selected (this class is defined in the STYLE block added in step 1), as well as override the getTabGroup and getContentPanelGroup methods of the Spry Tabbed panel object to use the functions defined in the SCRIPT block added in step 1.
Now preview your page. The bottom and top tabs should work correctly. Note: The bottom tabs will not look correct in Dreamweaver's design view due to how Dreamweaver handle's the display of Spry widgets is not compatible with the changes made above. In particular, in design view you will likely see the content of each tab, and only see the first tab displayed.
Labels: Spry



7 Comments:
Great Code. However, I was wondering if you one-up this tweak and help me out: I'm searching for a way to have a box with a total of 7 tabs, four on the top and three on the bottom. They would switch out the same middle table.
The design I'm working on can't fit all seven of these "quick info" tabs on top (and even if it could, it'd look overwhelming). So, having three of them appear on the bottom would be ideal.
What I'm looking for is close to what you came up with, having top and bottom tabs on the same page, but if I tested out your tab code correctly, it's for separate menus. I'm hoping to combine it into one.
Any thoughts/solutions?
Dewy2500,
I think that it may be possible to accomplish what you're looking for, but it would likely take a good bit of reworking the Spry code to handle the tab elements at the top and the bottom. Currently the code expects that there is a single element that contains each of the tabs. To put the tabs at top and bottom would require re-writting it to handle multiple tab container. Then from there, you'd need to re-write the code that changes the CSS class of the tabs so that the top tabs add and remove their bottom border based on which tab is selected, and then also swap out the class for the bottom tabs to add and remove the top border.
All in all, I'd think that you could find a tab control that already handles top and bottom tabs in the same control, or switch to a better widget that accommodates the number of categories that you're needing to display. Maybe make the control wider, or split out to two different tab controls.
Thanks for the reply. I think I accomplished it using normal tabs HTML and referring to the same table name. Lots of trial and error. I'll give you a live link when it launches. I'm 95% done my design and now the trick is to find a CMS to code the entire thing (learning or getting some one to help out). It's a successor to my 10-year-old site http://www.GamingTarget.com and I'm thinking about a modified WordPress...if that's possible? Right now we're using a good custom php CMS, but it's outdated. Any suggestions?
Glad that you got it working. I'd be interested in seeing what changes you made.
I've not used Spry with WordPress or any other CMS (I've always rolled my own for the particular requirements of a site, but going forward I expect to use such a system). I'd guess that it would be fairly easy to make sure the Spry files were linked in, but not sure how it would only link them in when needed rather than on all pages. Each CMS would probably handle that differently.
Or thinking more on it, were you asking if a CMS allow the end user to edit the number of tabs as well as their positions. That I'd think might be more tricky.
I don't know if this is still an active thread or not but I have a question relating to nested tabs (tabs within tabs). I HOPE it is because I'm stuck.
I have a page that contains a Spry tabbed contol and on each of the three tabs, there is another (nested) tabbed control, for a total of 4 tabbed controls. Each of the tabbed controls on the three main tabs contain 2 tabs.
To be perfectly clear, Tab1 of the main tabbed control has a nested tabbed control with 2 tabs. Tab2 of the main tabbed control has a nested tabbed control with 2 tabs and Tab3 of the main tabbed control has a nested tabbed control with 2 tabs.
My problem is linking to this page from another page (or from a link on another site) to display a specific tab on nested tab control.
I am familiar with the SpryURLUtils.js file and passing parameters to a page containing a tabbed control, but all the documentation and tutorials I've read only relate to ONE tabbed control and NOT to nested tabbed controls. For example;
target.html?tab=1#TabbedPanels1
And that works fine but doesn't allow me to specify which tab on the nested tabbed control I want displayed, which is why I'm asking if you know of a method or how to link to nested tabs within a tabbed control.
I would greatly appreciate any help or advice you can offer.
AL
Al,
If you're familiar with SpryUrlUtil.js then one way to do it would be to have two query string parameters, one to open the parent tabbed panel, and another to open the nested tabbed panel to the correct panel. Such as:
target.html?parentTab=1&subTab=2
Actually, I already solved the problem by writing a separate javascript handler for passed parameters to each page containing nested tabbed panels. I did all this in the section at the bottom of the page (javascript section) where the default tabs are set (by passed params).
It's simple enough to pass basically anything you want to a page (via a link) and then write the params.whatever parsing mechanism to sort out the details of what you want to happen. That's what I did and it works well. I'm using a single 2-digit value (integer) to set both the main and the nested tabbed panels. Hey --- why NOT do it that way?
What this also allows me to do is to set the default tab for ALL the tabbed panels on each page, which as it turns out is rather handy.
One of the things I discovered is that when you pass params to a page that has nested tabbed panels is that the passed param for the second (nested) tabbed panel also sets the default panel for ALL the nested tabbed panels.
I'm sure that's an 'undocumented feature', albeit NOT a very good one, but at least I know about it (now).
At any rate, thanks for the feedback and for inspiring me to solve the problem on my own. It was a worth while experience.
Post a Comment
Links to this post:
Create a Link
<< Home