Created
October 14, 2013 10:29
-
-
Save robotdana/6973720 to your computer and use it in GitHub Desktop.
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
var comments; | |
$.fn.getComments = function(data) { | |
var template = data.template; | |
data.template = undefined; | |
var container = $(this).empty(); | |
data['thread:link'] = $('link[rel=canonical]').attr('href'); | |
data.limit = 100; | |
data.order = 'asc'; | |
$.getJSON('http://disqus.com/api/3.0/threads/listPosts.json', data, function(response){ | |
comments = response.response | |
$.each(comments, function(){ | |
container.append(template(this)); | |
}); | |
}); | |
return $(this); | |
} | |
$.formatDate = function(string) { | |
months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'] | |
date = new Date(string); | |
if (!isNaN(date)){ | |
return date.getDate() + ' ' + months[date.getMonth()] + ' ' + date.getFullYear(); | |
} else { | |
return string; | |
} | |
} | |
$.comment_template = function(comment) { | |
var link_href = comment.author.url !== '' ? ' href="' + comment.author.url + '"' : ''; | |
var link_tag = comment.author.url !== '' ? 'a' : 'span'; | |
return ('<section class="comment">' + | |
'<' + link_tag + link_href + ' class="name"><h1>' + comment.author.name + '</h1></' + link_tag + '>' + | |
'<' + link_tag + link_href + ' class="comment_avatar"><img src="http:' + comment.author.avatar.cache + '" /></' + link_tag + ' + >' + | |
comment.message + | |
'<time data-datetime="' + comment.createdAt + '">' + $.formatDate(comment.createdAt) + '</time><hr>' + | |
'</section>'); | |
} | |
$('#comments').remove(); | |
$(".entry:not('.next, .prev')").append('<div id="comments"></div>'); | |
$('#comments').getComments({template: $.comment_template, api_key: 'uHj7RQADleD7FSA8KXNIf2C9XmgqVlcE91jkffoICWlSkhsMt70Jv7OsyZgHJ3pD', forum:'danielsherson'}) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment