Created
January 9, 2011 00:42
-
-
Save kkaefer/771281 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
$(function() { | |
function pushState() { | |
var url = $(this).attr('href'); | |
replaceImage(url); | |
if (history.pushState) { | |
history.pushState({}, '', url); | |
} | |
return false; | |
} | |
function attachHandlers() { | |
$('a.previous-link, a.next-link') | |
.unbind('click', pushState) | |
.bind('click', pushState); | |
} | |
function replaceImage(url) { | |
$('.body').load(url + ' .body', attachHandlers); | |
$('.photo').css('opacity', 0.5); // Loading indicator ;) | |
} | |
$(window).bind('popstate', function(e) { | |
if (e.originalEvent.state) { | |
replaceImage(location.href); | |
} | |
}); | |
$(document).keydown(function(e){ | |
if (e.shiftKey || e.metaKey || e.ctrlKey || e.altKey || e.srcElement !== document.body) return; | |
if (e.keyCode == 37) $('a.previous-link').eq(0).click(); | |
else if (e.keyCode == 39) $('a.next-link').eq(0).click(); | |
}); | |
attachHandlers(); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Replace the
.body
selector with the fragment of the page that you want to replace.