Changed tab handling from binding a click handler on each tab to a <body> delegate targeting the same tabs

This commit is contained in:
Scott Rabin 2011-09-09 12:07:59 -04:00
parent 3f12a6877e
commit c268f236f0

View File

@ -13,30 +13,24 @@ $(document).ready(function() {
/* Tabs Activiation /* 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 //Let go if not a hashed one
var tab = $(this).find('> li > a'); if(contentLocation.charAt(0)=="#") {
tab.click(function(e) {
//Get Location of tab's content e.preventDefault();
var contentLocation = $(this).attr('href');
//Let go if not a hashed one //Make Tab Active
if(contentLocation.charAt(0)=="#") { $(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');
}
});
}); });
}); });