Created
April 10, 2014 18:02
-
-
Save vrej/10407453 to your computer and use it in GitHub Desktop.
Murad Tabs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Author : Vrej | |
* Date: 02 20 14 | |
*/ | |
jQuery(function($) { | |
//taking care of initial sho and hide | |
//all the first elements are set to show and rest will be hidden | |
$('#murad-tabs > ul li a:not(:first)').addClass('inactive'); | |
$('#murad-tabs .murad-sub-tabs li a:not(:first)').addClass('inactive'); | |
$('.murad-tabs-container').hide(); | |
$('.murad-sub-tabs-container').hide(); | |
$('.murad-tabs-container:first').show(); | |
$('.murad-sub-tabs-container:first').show(); | |
//looping true all the titles and containers to add unique ID | |
//top level tabs | |
var i = 1 | |
$("#murad-tabs li a").each( function() { | |
$(this).attr("id","tabs-"+i); | |
i++; | |
}); | |
i = 1; | |
$(".murad-tabs-container").each( function() { | |
$(this).attr("id","tabs-"+i+"-C"); | |
i++; | |
}); | |
//second level tabs | |
var b = 1 | |
$(".murad-sub-tabs li a").each( function() { | |
$(this).attr("id","sub-tabs-"+b); | |
b++; | |
}); | |
b = 1; | |
$(".murad-sub-tabs-container").each( function() { | |
$(this).attr("id","sub-tabs-"+b+"-C"); | |
b++; | |
}); | |
//handling the events on top level tabs | |
$('#murad-tabs > ul li a').click(function(event){ | |
event.preventDefault(); | |
var uniqueId = $(this).attr("id"); | |
//adding and removing active/inactive class on titles | |
if($(this).hasClass('inactive')){ | |
$('#murad-tabs > ul li a').addClass('inactive'); | |
$(this).removeClass('inactive'); | |
}; | |
$('.murad-tabs-container').hide(); | |
$('#'+ uniqueId +'-C').show(); | |
return false; | |
}); | |
$('.murad-sub-tabs li a').click(function(event){ | |
event.preventDefault(); | |
var uniqueId = $(this).attr("id"); | |
if($(this).hasClass('inactive')){ | |
$('.murad-sub-tabs li a').addClass('inactive'); | |
$(this).removeClass('inactive'); | |
}; | |
$('.murad-sub-tabs-container').hide(); | |
$('#'+ uniqueId +'-C').show(); | |
return false; | |
}); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment