Skip to content

Instantly share code, notes, and snippets.

@ishouvik
Created February 24, 2014 13:43
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ishouvik/9188650 to your computer and use it in GitHub Desktop.
Save ishouvik/9188650 to your computer and use it in GitHub Desktop.
Javascript:TwitterBootstrap: bootstrap_tab_bookmark.js
function bootstrap_tab_bookmark (selector) {
if (selector == undefined) {
selector = "";
}
var bookmark_switch = function () {
url = document.location.href.split('#');
if(url[1] != undefined) {
$(selector + '[href=#'+url[1]+']').tab('show');
}
}
/* Automagically jump on good tab based on anchor */
$(document).ready(bookmark_switch);
$(window).bind('hashchange', bookmark_switch);
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