My apologies for adding yet another jQuery question but I've been banging my head against this code for far too long. The following code is used on my website: brianjenkins94.tumblr.com in order to fill the #iframe div with the corresponding content loaded via $.get(). The nav works properly (save the obnoxious page jumps occurring from the unconfigured scrollzer & scrolly libraries) but I have yet to be able to figure out how to restore the page content based upon what is provided by the document.location.hash property. If anyone could identify why this code is nonfunctional or perhaps provide some insight as to whether there's a better way of going about doing this, it would be greatly appreciated.
Thanks ahead of time, Brian
$(document).ready(function() {
console.log("Executing embedded jQuery.")
if (document.location.hash.length == 0) {
$("#home")[0].click();
console.log("Simulating #home link click.");
} else {
$(document.location.hash)[0].click();
console.log("Simulating " + document.location.hash + " link click.");
}
$("#header #nav a").click(function() {
if (!$(this).hasClass("active")) {
$("#nav a").removeClass("active");
$(this).addClass("active");
document.location.hash = $(this).attr('href');
switch (document.location.hash) {
case "#home":
$.get("{text:DocumentRoot}index.html", function(data) {
$("#iframe").html(data);
console.log("Loaded index.html");
});
break;
case "#showcase":
$.get("{text:DocumentRoot}showcase.html", function(data) {
$("#iframe").html(data);
console.log("Loaded showcase.html");
});
break;
case "#about":
$.get("{text:DocumentRoot}about.html", function(data) {
$("#iframe").html(data);
console.log("Loaded about.html");
});
break;
case "#github":
$.get("{text:DocumentRoot}github.html", function(data) {
$("#iframe").html(data);
console.log("Loaded github.html");
});
break;
default:
console.log("No corresponding page.")
event.preventDefault();
break;
}
}
});
});
Edit: {text:DocumentRoot} is a tumblr placeholder value I set to: https://rawgit.com/brianjenkins94/Sites/master/