Created
February 6, 2013 10:50
-
-
Save JensRantil/4721860 to your computer and use it in GitHub Desktop.
Code that makes it possible to link directly to a nested (Bootstrap) tab. Also, see http://stackoverflow.com/questions/7862233/twitter-bootstrap-tabs-go-to-specific-tab-on-page-reload
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
function handleTabLinks() { | |
var hash = window.location.href.split("#")[1]; | |
if (hash !== undefined) { | |
var hpieces = hash.split("/"); | |
for (var i=0;i<hpieces.length;i++) { | |
var domelid = hpieces[i]; | |
var domitem = $('a[href=#' + domelid + '][data-toggle=tab]'); | |
if (domitem.length > 0) { | |
if (i+1 == hpieces.length) { | |
// last piece | |
setTimeout(function() { | |
// Highly unclear why this code needs to be inside a timeout call. | |
// Possibly due to the fact that the first ?.tag('show') call needs | |
// to have it's animation finishing before the next call is being | |
// made. | |
domitem.tab('show'); | |
}, | |
// This magic timeout is based on trial and error. I bumped it | |
// partially to catch the visitor's attention. | |
1000); | |
} else { | |
domitem.tab('show'); | |
} | |
} | |
} | |
} | |
} | |
jQuery.ready(function() { | |
handleTabLinks(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I just want to ask regarding what if the links is from other page then it will trigger the specific tab with tab content