Skip to content

Commit

Permalink
feat(tab): auto activate first tab if no active specified
Browse files Browse the repository at this point in the history
  • Loading branch information
prudho authored and Sean committed Sep 1, 2019
1 parent bf92e99 commit 3e129a0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/definitions/modules/tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,11 @@ $.fn.tab = function(parameters) {
initializedHistory = true;
}

if(module.determine.activeTab() == null) {
module.debug('No active tab detected, setting first tab active', module.get.initialPath());
module.changeTab(module.get.initialPath());
};

module.instantiate();
},

Expand Down Expand Up @@ -679,6 +684,29 @@ $.fn.tab = function(parameters) {
}
},

determine: {
activeTab: function() {
var activeTab = null;

$tabs.each(function(_index, tab) {
var $tab = $(tab);

if( $tab.hasClass(className.active) ) {
var
tabPath = $(this).data(metadata.tab),
$anchor = $allModules.filter('[data-' + metadata.tab + '="' + module.escape.string(tabPath) + '"]')
;

if( $anchor.hasClass(className.active) ) {
activeTab = tabPath;
}
}
});

return activeTab;
}
},

utilities: {
filterArray: function(keepArray, removeArray) {
return $.grep(keepArray, function(keepValue) {
Expand Down

0 comments on commit 3e129a0

Please sign in to comment.