Skip to content

Instantly share code, notes, and snippets.

@mikevalstar
Created November 15, 2011 18:52
Show Gist options
  • Select an option

  • Save mikevalstar/1367956 to your computer and use it in GitHub Desktop.

Select an option

Save mikevalstar/1367956 to your computer and use it in GitHub Desktop.
function loadPage(hash, fn){
if(!hash || hash == ''){
if(typeof _gaq !== 'undefined')
_gaq.push(['_trackPageview']);
return; // nothing to do
}
var url = (hash[0] == '#') ? hash.substring(2): hash;
$('#C').html('Loading Content...'); // replace with loading screen code
var callback = function(responseText, textStatus, XMLHttpRequest){
$(document).attr('title', $(responseText).filter('title').text());
if(fn) fn();
// track the page view
if(typeof _gaq !== 'undefined')
_gaq.push(['_trackPageview', url]);
}
$('#C').load(url + ' #C', callback);
}
$("a").live("click", function(event){
var href = $(this).attr("href");
if(href[0] == "/"
&& href.substring(href.length - 4) != '.png'
&& href.substring(href.length - 4) != '.jpg'
&& href.substring(href.length - 5) != '.jpeg'
&& href.substring(href.length - 4) != '.gif' ){
event.preventDefault();
window.location.hash = "#!" + href;
}
});
$(window).bind('hashchange', function(){
loadPage( location.hash );
});
loadPage( location.hash, false );
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment