Skip to content

Instantly share code, notes, and snippets.

@thirdender
Created February 2, 2012 20:16
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thirdender/1725514 to your computer and use it in GitHub Desktop.
Save thirdender/1725514 to your computer and use it in GitHub Desktop.
Example fragment loading using pjax: https://github.com/defunkt/jquery-pjax
// Handle previous/next navigation
$(function() {
// Requires jQuery 1.7+ to utilize the new "on" event attachment
$("#contentPadding").on("click", "a.prev, a.next", function (event) {
$.pjax({
"url": $(this).attr("href"),
"fragment": "#contentPadding",
"container": "#contentPadding",
"complete": function(data) {
// Update the className on the BODY tag
var bodyClass = data.responseText && data.responseText.match(/<body[^>]+class\s*=\s*['"]([^'"]+)/);
if (bodyClass) {
$("body").attr("class", bodyClass[1]);
}
// Reinitialize AddThis if it's inside the loaded fragment
if (window.addthis) {
addthis.toolbox($(".addthis_toolbox").get(0));
addthis.counter($(".addthis_counter").get(0));
}
}
});
event.preventDefault();
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment