Skip to content

Instantly share code, notes, and snippets.

@johnw86
Last active August 29, 2015 13:59
Show Gist options
  • Save johnw86/10657530 to your computer and use it in GitHub Desktop.
Save johnw86/10657530 to your computer and use it in GitHub Desktop.
Load Disqus comments on click
/* Disqus load comments */
$('#load-comments').on('click', function (e) {
e.preventDefault();
var loadBtn = $(this);
if (!loadBtn.hasClass('disabled')) {
loadBtn.addClass('disabled');
//Remove any old errors
$("#content").find('.comments_error').remove();
var disqus_shortname = loadBtn.data('disqus-shortname');
disqus_identifier = "nid-" + loadBtn.data('disqus-identifier');
// ajax request to load the disqus javascript
$.ajax({
type: "GET",
url: "http://" + disqus_shortname + ".disqus.com/embed.js",
dataType: "script",
cache: true
}).done(function () {
loadBtn.hide();
}).fail(function () {
loadBtn.after('<p class="error comments_error">Sorry an error seems to have occurred attempting to load the comments, please try again later.</p>');
loadBtn.removeClass('disabled');
});
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment