Created
February 2, 2012 20:16
-
-
Save thirdender/1725514 to your computer and use it in GitHub Desktop.
Example fragment loading using pjax: https://github.com/defunkt/jquery-pjax
This file contains 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
// 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