Skip to content

Instantly share code, notes, and snippets.

@KempfCreative
Created October 19, 2013 22:56
Show Gist options
  • Save KempfCreative/7062582 to your computer and use it in GitHub Desktop.
Save KempfCreative/7062582 to your computer and use it in GitHub Desktop.
This is a module used in a larger JS file that adds classes to the selected navigation tab.
tabs: function (element, hover) {
var scope = element,
$contentTabs = $jQ(scope + ' > .tab-content > .tab'),
activeClass = 'active';
$jQ(scope + ' > .tab-menu > .tab').each(function (i, el) {
$jQ(this).add($contentTabs[i]).attr('tab', i + 1);
});
$jQ(scope + ' > .tab-menu > .tab').on((hover ? 'mouseenter' : 'click'), function (e) {
if (!hover) {
e.preventDefault();
}
var tab = $jQ(this).attr('tab');
$jQ(scope + ' > .tab-menu > .tab').add(scope + ' > .tab-content > .tab').removeClass(activeClass);
$jQ(this).add(scope + ' > .tab-content > .tab[tab=' + tab + ']').addClass(activeClass);
});
$jQ(scope + ' > .tab-menu > .tab:first-child').add(scope + ' > .tab-content > .tab:first-child').addClass(activeClass);
},
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment