Last active
August 29, 2015 13:59
-
-
Save johnw86/10657530 to your computer and use it in GitHub Desktop.
Load Disqus comments on click
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
/* 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