Created
May 16, 2013 06:21
-
-
Save pradeepn/5589747 to your computer and use it in GitHub Desktop.
Bootstrap Tab Activation From Url. 1. Works for all kinds of bootstrap tabs and nested tabs 2. In order to work for nested tabs add class nested to the data-toggle="tab" a tag for all child tabs
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
var handleUrlTabActivation = function () { | |
var hash = document.location.hash; | |
if(hash!=null && hash != ""){ | |
hash = hash.split('#')[1]; | |
} | |
console.log(hash); | |
var prefix = "tab-"; | |
var hpieces = hash.split('/'); | |
for (var i = 0; i < hpieces.length; i++) { | |
var domelid = hpieces[i].replace(prefix, ''); | |
console.log(domelid); | |
var domitem = $('a[href=#' + domelid + '][data-toggle=tab]'); | |
console.log(domitem); | |
if (domitem.length > 0) { | |
domitem.tab('show'); | |
} | |
} | |
$('a[data-toggle=tab]').on('shown', function (e) { | |
if ($(this).hasClass('nested')) { | |
var nested = window.location.hash.split('/'); | |
window.location.hash = nested[0] + '/' + prefix + e.target.hash.split('#')[1]; | |
} else { | |
window.location.hash = e.target.hash.replace('#', '#' + prefix); | |
} | |
}); | |
} | |
$(document).ready(function(){ | |
handleUrlTabActivation(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment