Created
May 21, 2013 19:11
-
-
Save brettsnippets/5622391 to your computer and use it in GitHub Desktop.
JavaScript: Ajax Call, Using Push State & Disqus Commenting Reload
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
$.ajaxSetup({cache:false}); | |
$(document).on("click", ".resource-listing a.read-more", function(){ | |
if(Modernizr.history) { | |
var post_url = $(this).attr('href'); | |
var post = $('#main-content'); | |
post.html('<img src="/wp-content/themes/funding/assets/img/ajax-loader.gif" class="ajax-loader"/>'); /* shows ajax loader until content is loaded */ | |
post.load(post_url + ' #pull-this-content', function() { | |
history.pushState({page: post_url}, '', post_url); | |
var disqus_shortname = 'fundinglongevity'; | |
$.ajax({ | |
type: "GET", | |
url: "http://" + disqus_shortname + ".disqus.com/embed.js", | |
dataType: "script", | |
cache: true | |
}); | |
}); | |
/* within the #post-here div, this will load in the post url from the a:link being clicked, | |
the #post- is pulling in the div that contains the content we want to bring in, instead of pulling | |
in the entire page. This could easily be anything like, #pull-this-content, it doesn't have to contain the post id */ | |
return false; // this just tells the browser that the link shouldn't behave like a typical link | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment