Skip to content

Instantly share code, notes, and snippets.

@clarkf
Created January 31, 2011 10:55
Show Gist options
  • Save clarkf/803896 to your computer and use it in GitHub Desktop.
Save clarkf/803896 to your computer and use it in GitHub Desktop.
// Check for hash value in URL
var hash = window.location.hash.substr(1);
//Check to ensure that a link with href == hash is on the page
if ($('a[href="' + hash + '"]').length) {
//Load the page.
var toLoad = hash + '.html #main-content';
$('#main-content').load(toLoad);
}
$('nav ul li a').click(function(){
if (window.location.hash.substring(1) == $(this).attr('href')) {
return false;
}
var toLoad = $(this).attr('href')+' #main-content';
$('#main-content').hide('fast',loadContent);
$('#load').remove();
$('#wrapper').append('<span id="load">LOADING...</span>');
$('#load').fadeIn('normal');
window.location.hash = $(this).attr('href').substr(0,$(this).attr('href').length-5);
function loadContent() {
$('#main-content').load(toLoad,'',showNewContent())
}
function showNewContent() {
$('#main-content').show('normal',hideLoader());
}
function hideLoader() {
$('#load').fadeOut('normal');
}
return false;
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment