Created
July 18, 2014 15:17
-
-
Save Nemo64/05cd841d886b6de405fb to your computer and use it in GitHub Desktop.
remember which bootstrap tab was active while navigating. This is a very cheap cookie trick and it requires jquery-cookie.
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
// behavior for tabs | |
// FIXME can create unexpected behavior with multiple tabs on one page, also with multiple browser tabs/windows | |
$(document).on('click', '[data-toggle="tab"], [data-toggle="pill"]', function(event) { | |
var hash = $.prop(this, "hash"); | |
$.cookie('active-tab', hash, { path: '/' }); | |
}); | |
$(window).on('popstate hashchange ready load', function() { | |
var cookieTab = $.cookie('active-tab'); | |
var tab = cookieTab || null; | |
if (tab !== null) { | |
$('a[href="' + tab + '"]').tab('show'); | |
} | |
}); | |
// if any tab has an errornous form type display it | |
$(window).on('ready load', function() { | |
var $tabs = $('.tab-content'); | |
$tabs.on('invalid.tabs', '.tab-pane[id]', function () { | |
$('a[href="#' + this.id + '"]').tab('show'); | |
}); | |
// trigger invalid on the first error | |
$tabs.find('.has-error:first').trigger('invalid.tabs'); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment