Hey, I found it by myself! The cookie isn’t stored at every tab click, but only when going out of the page. Here’s the JS code (which not uses Tabs plugin, but the Cookie one):
;(function($) { // Wrapper to prevent errors with other scripts
$(document).ready(function() { // jQuery has a simple statement that checks the document and waits until it's ready to be manipulated, known as the ready event
var curChildIndex; // Define as global
if($.cookie('active_tab') == null) { // If no cookie is set…
$('ul.tabNav li:first').addClass('current'); // …mark as current the first Title item
$('.tabContainer .tab:first').addClass('current').slideDown('fast', myClick); // …show the first tab content
} else {
var cookieChildIndex = $.cookie('active_tab');
$('ul.tabNav li:nth-child('+cookieChildIndex+')').addClass('current'); // …mark as current the Title item stored in cookie
$('.tabContainer div:nth-child('+cookieChildIndex+')').addClass('current').slideDown('fast', myClick); // …show the content of the corresponding tab
}
function myClick() {
$('ul.tabNav a').click( // On click…
function() {
curChildIndex = $(this).parent().prevAll().length + 1; // Sets the current li index
$(this).parent().parent().children('.current').removeClass('current'); // Remove the old current class from li
$(this).parent().addClass('current'); // Adds the current class to the current li
$(this).parent().parent().next('.tabContainer').children('.current').slideUp('fast',function() { // Slides up the old tabContainer div (the current tab)
$(this).removeClass('current');
$(this).parent().children('div:nth-child('+curChildIndex+')').slideDown('normal',function() { // Slides down the new tabContainer div
$(this).addClass('current');
});
});
return false;
}
);
}
$('a').not($('ul.tabNav a')).click(function(){$.cookie('active_tab', curChildIndex)}); // Set a session cookie with the current li index when going to another page
})
})(jQuery);
It’s one of my first JS codes, don’t expect it to be a model…
Cheers,
Juan