© Kademi 2022
jQuery Comments v1.0.1
Configuration
Name | Type | Description |
---|---|---|
pageUrl | String | The url of the resource to add comments to. Must end with a slash |
streamSelector | String |
The selector of stream wrapper which wraps all comments |
renderCommentFn | Function | The callback function to render the markup for a comment. Takes the following arguments user, comment, commentDate, where user is an object containing name, href, photoHref |
clearContainerFn | Function | The callback function to clear the comments container. Takes no arguments |
ajaxLoadingFn | Function | The callback function to show ajax loading. Takes one argument isLoading (true/false) |
commentsPerPage | Number | The number of comments will be showed per page |
paginateFn | Function | The callback function to render the markeup for pagination |
passwordProperty | String | Property name to use in sending password to server |
aggregated | Boolean | If true will list all comments under the given page |
Default Configuration
{ pageUrl: window.location, streamSelector: ".comments-stream", renderCommentFn: function(user, date, comment, commentId) { log("renderCommentFn-101-standard", user, "container=", container, "commentId=", commentId); if (user === null) { log("no user so dont render"); return; } var outerDiv = $("#" + commentId); log("outerDiv", commentId, outerDiv); if (outerDiv.length === 0) { log("add comment"); outerDiv = $("<div class='forumReply'></div>"); outerDiv.attr("id", commentId); var commentStream = container.find(config.streamSelector); flog("append to", commentStream, "sel", config.streamSelector); commentStream.append(outerDiv); var profilePic = profileImg(user); var profLink = $("<a class='profilePic' href='" + user.href + "'>" + profilePic + "</a>"); var nameLink = $("<a class='user' href='" + user.href + "'>" + user.name + "</a>"); var commentPara = $("<p class='cmt'></p>"); commentPara.html(comment); var dateSpan = $("<abbr title='" + date.toISOString() + "' class='auxText'>" + toDisplayDateNoTime(date) + "</abbr>"); var toolsDiv = $("<div></div>"); outerDiv.append(profLink); outerDiv.append(nameLink); outerDiv.append(commentPara); outerDiv.append(dateSpan); outerDiv.append(toolsDiv); } else { log("update"); // Just update outerDiv.find(".cmt").html(comment); } jQuery("abbr.auxText", outerDiv).timeago(); }, clearContainerFn: function() { container.find(config.streamSelector).html(""); }, ajaxLoadingFn: function(isLoading) { if (isLoading) { ajaxLoadingOn(); } else { ajaxLoadingOff(); } }, commentsPerPage: 10, paginateFn: function(comments, config, container) { log("paginateFn-101-standard", comments, config, container); var totalComments = comments.length; var commentsPerPage = config.commentsPerPage; if (totalComments > commentsPerPage) { container.prepend( '<div class="well well-sm text-center"><a href="" class="btn-show-more">Show previous comments</a></div>' ); var commentWrappers = container.find('.forumReply'); // Show 10 last comments commentWrappers.filter(':lt(' + (totalComments - commentsPerPage) + ')').hide().addClass('hidden-comment'); container.find('.btn-show-more').click(function(e) { e.preventDefault(); var hiddenCommentWrappers = commentWrappers.filter('.hidden-comment'); var totalHiddenComments = hiddenCommentWrappers.length; hiddenCommentWrappers.filter(':gt(' + (totalHiddenComments - commentsPerPage - 1) + ')').show().removeClass('hidden-comment'); if (totalHiddenComments <= commentsPerPage) { $(this).parent().hide(); } }); } }, aggregated: false }
Versions
Back to main page...
1.0.4
(Source code)
1.0.3
(Source code)
1.0.2
(Source code)
1.0.1
(Source code)
Hide comments
