Tabs 2.7: Flexibility
April 7th, 2007
- Category:
- JavaScript,
- Web Development,
- jQuery
I’ve added a few requested features and fixed some quirks for the Tabs plugin recently.
Increased flexibility
For a much increased flexibility regarding the HTML structure required for a tab interface you can now add particular classes to the unordered list and the tab containers. If no classes are present, the elements are queried relying on the default structure. The tabStruct option still works but is deprecated and will go away with the next release (Tabs 3).
Say you need a div wrapped around each the unordered list and the containers. Provide the following HTML:
<div id="container">
<div>
<ul class="tabs-nav">
…
</ul>
</div>
<div>
<div id="fragment-1" class="tabs-container">
…
</div>
<div id="fragment-2" class="tabs-container">
…
</div>
<div id="fragment-3" class="tabs-container">
…
</div>
</div>
</div>
That also means that you can easily switch the order of containers and the list:
<div id="container">
<div id="fragment-1">
…
</div>
<div id="fragment-2">
…
</div>
<div id="fragment-3">
…
</div>
<ul class="tabs-nav">
…
</ul>
</div>
As long as you attach these classes to the proper elements, you can go crazy with your HTML. The class names are even configurable via option. If the default structure is used, adding the class names does no harm but it is not required. They are of course required for the look of the tabs, but they are attached by the plugin if not present. The underlying (default) HTML becomes even more unobtrusive that way and it also becomes much easier to add fallback styles for the case of JavaScript being disabled.
Specify active tab by class
Instead of specifying the active tab when initializing tabs you can now also simply add the class to the list element representing the desired tab, like:
<li class="tabs-selected">
Please note that a given fragment identifier/hash in the URL will take precedence and the class will be removed if the active tab doesn’t match. Here’s how the active tab gets computed: fragment identifier overrules class overrules active tab given as parameter in the initialization.
onClick enhanced
Switching tabs is now canceled if the onClick callback returns false. This is useful for instance if proceeding to the next tab requires form validation before.
Some more changes
-
Triggering/Enabling/Disabling tabs can also be done via id instead of an index:
$('#tabs').triggerTab(1);is the same as
$('#tabs').triggerTab('#tab-1'); - Fixed a bug (duplicate ids) occuring when multiple Ajax tabs containers are included in the same page. Remote tabs are now numbered consecutively.
- There’s a new option
hashPrefixto define a string that is used as base for constructing the id of a remote tab, such as “#remote-tab-1″. - Finally tabs are looking better…
- I’ve fixed a few little quirks in IE introduced with the Ajax support. Along with that goes an update for the History plugin where I’ve fixed a minor bug that occured both in IE and Safari.
I consider this the last maintenance release for the Tabs plugin. After I’ve tackled Thickbox Reloaded I’m going to rewrite Tabs for Tabs 3, which will allow mixed static/Ajax tabs, easy creating and removing tabs, mouseover tabs…
73 Comments
Comments feed
Comment by Rikard, April 10th, 2007 at 3:36 pm
Comment by Noel, April 14th, 2007 at 11:18 am
Comment by Mark, April 14th, 2007 at 4:15 pm
Comment by Mark, April 15th, 2007 at 8:16 pm
Comment by James, April 16th, 2007 at 9:50 pm
Author Comment
Comment by Klaus, April 17th, 2007 at 7:07 am
Comment by Mark, April 17th, 2007 at 12:31 pm
Comment by Mark, April 17th, 2007 at 1:53 pm
Comment by Mark, April 17th, 2007 at 1:55 pm
Comment by Dave, April 20th, 2007 at 12:16 am
Comment by Daemach, April 20th, 2007 at 7:26 pm
Author Comment
Comment by Klaus, April 21st, 2007 at 10:00 am
Comment by Ross, April 24th, 2007 at 3:42 am
Comment by Jeremy, April 26th, 2007 at 3:33 pm
Comment by hyrcan, April 27th, 2007 at 5:37 pm
Comment by hyrcan, April 27th, 2007 at 5:41 pm
Comment by Láďa, April 29th, 2007 at 10:55 am
Author Comment
Comment by Klaus, April 29th, 2007 at 12:24 pm
Comment by Láďa, May 1st, 2007 at 3:13 pm
Comment by Láďa, May 1st, 2007 at 4:24 pm
Comment by wolvman, May 2nd, 2007 at 2:25 pm
Comment by extent, May 4th, 2007 at 4:27 am
Comment by Dave Schlaegel, May 4th, 2007 at 5:33 pm
Comment by Dave Schlaegel, May 4th, 2007 at 5:36 pm
Comment by extent, May 5th, 2007 at 12:50 am
Comment by extent, May 5th, 2007 at 12:52 am
Comment by alexander farkas, May 5th, 2007 at 10:40 am
Author Comment
Comment by Klaus, May 5th, 2007 at 11:09 am
Comment by extent, May 5th, 2007 at 6:13 pm
Comment by alexander farkas, May 6th, 2007 at 9:57 am
Comment by tom, May 6th, 2007 at 6:40 pm
Comment by Rolley, May 7th, 2007 at 12:31 am
Comment by Rolley, May 7th, 2007 at 12:32 am
Comment by Michelle, May 7th, 2007 at 7:32 pm
Comment by Patrick Harris, May 10th, 2007 at 12:04 am
Comment by Phil Gyford, May 11th, 2007 at 8:27 pm
Comment by Ian, May 13th, 2007 at 9:28 am
Comment by Teamon, May 13th, 2007 at 3:43 pm
Comment by Teamon, May 13th, 2007 at 3:44 pm
Comment by Newbie to Tabs 2.x, May 15th, 2007 at 9:10 am
Comment by Newbie to Tabs 2.x, May 15th, 2007 at 9:11 am
Comment by Michael, May 17th, 2007 at 9:38 pm
Comment by Michael, May 17th, 2007 at 9:41 pm
Comment by Ed, May 24th, 2007 at 5:49 pm
Comment by extent, May 25th, 2007 at 10:54 am
Comment by Lars Nørgaard, May 26th, 2007 at 8:11 pm
Comment by Lars Nørgaard, May 26th, 2007 at 8:12 pm
Comment by Lars Nørgaard, May 26th, 2007 at 8:14 pm
Comment by bw, June 4th, 2007 at 3:54 pm
Comment by Ever, June 8th, 2007 at 7:29 am
Comment by bw, June 11th, 2007 at 11:20 am
Comment by alexander farkas, June 14th, 2007 at 1:59 pm
Comment by Paolo, June 19th, 2007 at 12:37 pm
Comment by Corey Stroeder, June 20th, 2007 at 9:34 pm
Comment by Paul, June 28th, 2007 at 8:51 pm
Comment by Marc, June 29th, 2007 at 5:16 pm
Comment by Marc, June 29th, 2007 at 5:21 pm
Author Comment
Comment by Klaus, June 29th, 2007 at 7:24 pm
Comment by Case, July 2nd, 2007 at 10:10 am
Comment by Matthew Moore, July 25th, 2007 at 5:23 pm
Comment by chris Corwin, August 9th, 2007 at 3:19 am
Comment by Nagesh, August 13th, 2007 at 4:44 pm
Comment by SeanJuan, August 23rd, 2007 at 6:19 am
Comment by Ryan, August 31st, 2007 at 4:28 pm
Comment by Joe, September 5th, 2007 at 10:15 pm
Author Comment
Comment by Klaus, September 6th, 2007 at 10:08 am
Comment by Matthew Moore, September 10th, 2007 at 10:55 pm
Comment by Matthew Moore, September 10th, 2007 at 10:57 pm
Author Comment
Comment by Klaus, September 11th, 2007 at 10:10 am
Comment by Philip Hunt, September 11th, 2007 at 8:48 pm
Author Comment
Comment by Klaus, September 11th, 2007 at 8:59 pm
Comment by Aaron, September 26th, 2007 at 5:35 pm
Comment by Greg, October 12th, 2007 at 10:06 pm