From c268f236f0462df58f0075ff164eef2251cfeedf Mon Sep 17 00:00:00 2001 From: Scott Rabin Date: Fri, 9 Sep 2011 12:07:59 -0400 Subject: [PATCH] Changed tab handling from binding a click handler on each tab to a delegate targeting the same tabs --- javascripts/tabs.js | 32 +++++++++++++------------------- 1 file changed, 13 insertions(+), 19 deletions(-) diff --git a/javascripts/tabs.js b/javascripts/tabs.js index 8a74b10..8ef1f99 100644 --- a/javascripts/tabs.js +++ b/javascripts/tabs.js @@ -13,30 +13,24 @@ $(document).ready(function() { /* Tabs Activiation ================================================== */ - var tabs = $('ul.tabs'); + $('body').delegate('ul.tabs > li > a', 'click', function(e) { - tabs.each(function(i) { + //Get Location of tab's content + var contentLocation = $(this).attr('href'); - //Get all tabs - var tab = $(this).find('> li > a'); - tab.click(function(e) { + //Let go if not a hashed one + if(contentLocation.charAt(0)=="#") { - //Get Location of tab's content - var contentLocation = $(this).attr('href'); + e.preventDefault(); - //Let go if not a hashed one - if(contentLocation.charAt(0)=="#") { + //Make Tab Active + $(this).parent().siblings().children('a').removeClass('active'); + $(this).addClass('active'); - e.preventDefault(); + //Show Tab Content & add active class + $(contentLocation).show().addClass('active') + .siblings().hide().removeClass('active'); - //Make Tab Active - tab.removeClass('active'); - $(this).addClass('active'); - - //Show Tab Content & add active class - $(contentLocation).show().addClass('active').siblings().hide().removeClass('active'); - - } - }); + } }); }); \ No newline at end of file