| 1 |
function commentify(site, fid) {
|
| 2 |
var stylepath = 'http://dev1.lowcountrynewspapers.com/sites/dev1.lowcountrynewspapers.com/modules/commentify/';
|
| 3 |
var imagepath = 'http://dev1.lowcountrynewspapers.com/sites/dev1.lowcountrynewspapers.com/modules/commentify/images/';
|
| 4 |
|
| 5 |
// Some customization is required here. Change the first element to your target for displaying the comments list
|
| 6 |
$("#commentcontainer").append('<div id="comments"><span><img id="togglecomments" src="' + imagepath + 'minus.png" title="show/hide comments"/> Comment on this</span></div>');
|
| 7 |
$("head").append('<link rel="stylesheet" href="' + stylepath + 'comments.css" type="text/css" media="screen" title="no title" charset="utf-8" />');
|
| 8 |
$.getJSON(site + "/" + fid + "&callback=?",
|
| 9 |
function(data){
|
| 10 |
|
| 11 |
$.each(data.comments, function(i,comment){
|
| 12 |
var box = $("<div></div>").appendTo("#comments");
|
| 13 |
$('<p></p>').text(comment.comment.replace(/(<([^>]+)>)/ig,"")).appendTo(box);
|
| 14 |
$('<div class="subj"></div>').text((i+1) + ") " + comment.subject).prependTo(box.find("p"));
|
| 15 |
var cdate = new Date();
|
| 16 |
cdate.setTime(comment.timestamp*1000);
|
| 17 |
$('<div></div>').html('Posted by <a href="' + data.url.replace(/story.*/,"user/") + comment.name + '">' + comment.name + '</a>, ' + cdate.toLocaleString() ).addClass("info").appendTo(box);
|
| 18 |
});
|
| 19 |
|
| 20 |
// Uncomment the following if you have jquery cookie plugin
|
| 21 |
|
| 22 |
// if($.cookie('showinlinecomments') == 0){
|
| 23 |
// $("#comments > *:gt(0)").hide();
|
| 24 |
// $("#comments span img").attr("src",imagepath + "plus.png");
|
| 25 |
// }
|
| 26 |
|
| 27 |
// Again with the changes. #commentcounter element is where to display count
|
| 28 |
$("<a>").attr('href','#comments').text('(0) Comments').appendTo("#commentcounter");
|
| 29 |
|
| 30 |
if (data.count > 0) {
|
| 31 |
$("#comments span").append(" (Showing " + data.comments.length + " of " + data.count +")");
|
| 32 |
$("#commentcounter a").text('('+data.count+') Comments');
|
| 33 |
$("#comments").append('<div class="tools"><a href="' + data.url.replace(/node/,"comment/reply") + '">Add your own comment</a> (Free Registration Required) | <a href="' + data.url + '">View all</a></div>');
|
| 34 |
} else {
|
| 35 |
$("#comments").append('<div class="tools"><a href="javascript:document.commentform.submit();">No comments yet, be the first</a></div>');
|
| 36 |
}
|
| 37 |
}
|
| 38 |
);
|
| 39 |
$('#comments span').toggle(
|
| 40 |
function(){
|
| 41 |
$("#comments > *:gt(0)").slideUp();
|
| 42 |
$("#comments span img").attr("src",imagepath + "plus.png");
|
| 43 |
// $.cookie('showinlinecomments',0,{ expires: 365 });
|
| 44 |
},
|
| 45 |
function(){
|
| 46 |
$("#comments > *:gt(0)").slideDown();
|
| 47 |
$("#comments span img").attr("src",imagepath + "minus.png");
|
| 48 |
// $.cookie('showinlinecomments',1,{ expires: 365 });
|
| 49 |
}
|
| 50 |
);
|
| 51 |
|
| 52 |
}
|