Skip to content

Instantly share code, notes, and snippets.

@ameliaikeda
Created February 3, 2014 22:32
Show Gist options
  • Save ameliaikeda/8793842 to your computer and use it in GitHub Desktop.
Save ameliaikeda/8793842 to your computer and use it in GitHub Desktop.
$(window).on("statechange", function(event) {
var state = History.getState();
var root = History.getRootUrl();
var uri = state.url.replace(root, "/");
var $next = $("[data-uri='" + uri + "']");
if ($next.length) {
// we've been to this page before.
var $current = $("#radio-container > .current");
$current.removeClass("current").hide();
$next.addClass("current").show();
} else {
// we need to fetch it and append it
$.ajax({
url: uri,
type: "GET",
dataType: "html",
success: function(data) {
if (data) {
var $section = $(data);
var $current = $("#radio-container > .current");
$current.removeClass("current").hide();
$section.appendTo($("#radio-container")).addClass("current").show();
handlers();
}
}
})
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment