Guest User

Untitled

a guest
Jul 19th, 2018
101
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.08 KB | None | 0 0
  1. jQuery.fn.tab_nav = function(settings) {
  2. settings = jQuery.extend({
  3. active_class: 'active',
  4. return_act : false
  5. },settings);
  6. var s = settings,
  7. $el = jQuery(this),
  8. $tab_links = $el.find('a'),
  9. $is_active = $el.find('.'+s.active_class);
  10. // Set first tab as active on document ready
  11. if ( $is_active.length ) {
  12. for ( var i = 0, len = $tab_links.length; i < len; i++ ){
  13. jQuery('#' + $tab_links[i].href.split('#')[1] ).hide();
  14. }
  15. jQuery('#'+ $is_active.find('a').attr('href').split('#')[1] ).show();
  16. } else {
  17. jQuery($tab_links[0]).closest('li').addClass(s.active_class);
  18. for ( var i = 1, len = $tab_links.length; i < len; i++ ){
  19. jQuery('#' + $tab_links[i].href.split('#')[1] ).hide();
  20. }
  21. }
  22. // Event detection and delegation
  23. jQuery(this).delegate('a', 'click', function(){
  24. var $oldActive = $el.find('.'+s.active_class);
  25. jQuery('#'+ $oldActive.find('a').attr('href').split('#')[1] ).hide();
  26. $oldActive.removeClass(s.active_class);
  27. jQuery(this).closest('li').addClass(s.active_class);
  28. jQuery('#'+ jQuery(this).attr('href').split('#')[1] ).show();
  29. return false;
  30. });
  31. }
Add Comment
Please, Sign In to add comment