I have a script (from https://css-tricks.com/rethinking-dynamic-page-replacing-content/) to load content into a page without refreshing the entire page… works fine in non-WP sites but not in WP - where it seems to reload the entire page.
My knowledge of this stuff is extremely limited, so please excuse my ineptness.
Here’s the script:
$(function() {
if(Modernizr.history){
var newHash = "",
$mainContent = $("#main"),
$pageWrap = $("#wrapper"),
baseHeight = 0,
$el;
$pageWrap.height($pageWrap.height());
baseHeight = $pageWrap.height() - $mainContent.height();
$("nav").delegate("a", "click", function() {
_link = $(this).attr("href");
history.pushState(null, null, _link);
loadContent(_link);
return false;
});
function loadContent(href){
$mainContent
.find("#guts")
.fadeOut(0, function() {
$mainContent.hide().load(href + " #guts", function() {
$mainContent.fadeIn(0, function() {
$pageWrap.animate({
height: baseHeight + $mainContent.height() + "px"
});
});
$("nav a").removeClass("current");
console.log(href);
$("nav a[href$="+href+"]").addClass("current");
});
});
}
$(window).bind('popstate', function(){
_link = location.pathname.replace(/^.*[\\\/]/, ''); //get filename only
loadContent(_link);
});
} // otherwise, history is not supported, so nothing fancy here.
});