Skip to content

Instantly share code, notes, and snippets.

@navarr
Created February 12, 2010 03:46
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 navarr/302272 to your computer and use it in GitHub Desktop.
Save navarr/302272 to your computer and use it in GitHub Desktop.
Tabbed Navigation for fromREADtoGREEN.com - I'm so proud of it
document.loadFuncs = new Array;
function loadUp()
{
for(i = 0;i < document.loadFuncs.length;i++)
{
document.loadFuncs[i]();
}
}
function whenLoad(loadfunc)
{
document.loadFuncs[document.loadFuncs.length] = loadfunc;
}
function showTab(tab)
{
document.location.hash = "#tab-" + tab;
}
function setDefaultTab(tab)
{
document.defaultTab = tab;
}
function checkHash()
{
if(document.location.hash != document.lastHash)
{
if(!document.location.hash.split("#tab-")[1]) { tab = document.defaultTab; }
else { tab = document.location.hash.split("#tab-")[1]; }
if(document.getElementById("content-" + tab))
{
for(var i = 0; i < document.tabs.length; i++)
{
$("nav-" + document.tabs[i]).className = "";
$("content-" + document.tabs[i]).style.display = "none";
}
$("nav-" + tab).className = "active";
$("content-" + tab).style.display="block";
}
document.lastHash = document.location.hash;
}
}
whenLoad(checkHash);
whenLoad(function(){ setInterval(checkHash,100); });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment