For a new bootstrap website that I'm working on, I am sorting the active tab when the nav-tab stacks, so that the selected tab is always connected to the tab-pane. While this works, it feels like a hack to me. Is there a better way to accomplish this that preserves the original tab order?
Html markup:
<div id="tab-bundle" class="container-fluid">
@Html.HiddenFor(model => model.SelectedBundle)
<ul class="nav nav-tabs" id="coverageTabs">
<li><a href="#Minimum">@LanguageDb.Me.Minimum</a></li>
<li><a href="#Better">@LanguageDb.Me.Better</a></li>
<li><a href="#Best">@LanguageDb.Me.Best</a></li>
<li><a href="#Custom">@LanguageDb.Me.Custom</a></li>
</ul>
<div class="tab-content">
<div class="tab-pane active bg-info" id="ajaxPanel">
@Html.Partial("SelectedBundle", Model)
</div>
</div>
</div>
Javascript:
$(document).ready(function () {
var updateCoverage = function (e) {
e.preventDefault();
var $tab = $(this);
$('#SelectedBundle').val($(this).attr("href").substr(1));
$('#coverageTabs a').css({ backgroundColor: "", color: "" });
// ajax omitted for brevity
$tab.tab('show').css('background-color', $('#ajaxPanel').css('background-color')).css('color', $('#ajaxPanel').css('color'));
if ( $('#coverageTabs').width() < 768 ) {
$tab.closest('li').appendTo('#coverageTabs');
}
};
$('a[href=#' + $('#SelectedBundle').val() + ']').tab('show').css('background-color', $('#ajaxPanel').css('background-color')).css('color', $('#ajaxPanel').css('color')); ;
$('#coverageTabs a').click(updateCoverage);
});