Created
January 13, 2016 08:23
-
-
Save shanginn/2e7f93d3856a6cef03b4 to your computer and use it in GitHub Desktop.
Make Bootstrap 3 remember which tab they were on. Works only with one set of tabs.
This file contains hidden or 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
var $tabLinks = $('a[data-toggle="tab"]'); | |
if($tabLinks.length) { | |
var lastTab = localStorage.getItem('lastTab'); | |
$tabLinks.on('click', function (e) { | |
//save the latest tab; use cookies if you like 'em better: | |
localStorage.setItem('lastTab', $(e.target).attr('href')); | |
}); | |
//go to the latest tab, if it exists: | |
var $target = lastTab ? $('a[href="' + lastTab + '"]') : $tabLinks.first(); | |
$target.tab('show'); | |
} |
This file contains hidden or 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
var $tb=$('a[data-toggle="tab"]'),LS=localStorage,LT;if($tb.length){$tb.click(function(e){LS.setItem('LBT',$(e.target).attr('href'))});((LT=LS.getItem('LBT'))?$('a[href="'+LT+'"]'):$tb.first()).tab('show');} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment