Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- jQuery.fn.tab_nav = function(settings) {
- settings = jQuery.extend({
- active_class: 'active',
- return_act : false
- },settings);
- var s = settings,
- $el = jQuery(this),
- $tab_links = $el.find('a'),
- $is_active = $el.find('.'+s.active_class);
- // Set first tab as active on document ready
- if ( $is_active.length ) {
- for ( var i = 0, len = $tab_links.length; i < len; i++ ){
- jQuery('#' + $tab_links[i].href.split('#')[1] ).hide();
- }
- jQuery('#'+ $is_active.find('a').attr('href').split('#')[1] ).show();
- } else {
- jQuery($tab_links[0]).closest('li').addClass(s.active_class);
- for ( var i = 1, len = $tab_links.length; i < len; i++ ){
- jQuery('#' + $tab_links[i].href.split('#')[1] ).hide();
- }
- }
- // Event detection and delegation
- jQuery(this).delegate('a', 'click', function(){
- var $oldActive = $el.find('.'+s.active_class);
- jQuery('#'+ $oldActive.find('a').attr('href').split('#')[1] ).hide();
- $oldActive.removeClass(s.active_class);
- jQuery(this).closest('li').addClass(s.active_class);
- jQuery('#'+ jQuery(this).attr('href').split('#')[1] ).show();
- return false;
- });
- }
Add Comment
Please, Sign In to add comment