Created
February 14, 2014 16:13
-
-
Save emaildano/9003867 to your computer and use it in GitHub Desktop.
Make bootstrap tabs bookmarkable. c/o http://julien.danjou.info/blog/2012/twitter-bootstrap-tabs-bookmark
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
function bootstrap_tab_bookmark (selector) { if (selector == undefined) { | |
selector = ""; } | |
/* Automagically jump on good tab based on anchor */ | |
$(document).ready(function() { | |
url = document.location.href.split('#'); | |
if(url[1] != undefined) { | |
$(selector + '[href=#'+url[1]+']').tab('show'); | |
} | |
}); | |
var update_location = function (event) { | |
document.location.hash = this.getAttribute("href"); | |
} | |
/* Update hash based on tab */ | |
$(selector + "[data-toggle=pill]").click(update_location); | |
$(selector + "[data-toggle=tab]").click(update_location); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment