© Kademi 2022
jQuery Comments v1.0.2
Change log:
- https://github.com/Kademi/kademi-dev/issues/1490
- Improve logs
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) { flog("renderCommentFn-102-standard", user, "container=", container, "commentId=", commentId); if (user === null) { flog("no user so dont render"); return; } var outerDiv = $("#" + commentId); if (outerDiv.length === 0) { flog("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); flog("dt", date); var dt = { date: date.getDate(), month: date.getMonth(), year: date.getYear(), hour: date.getHours(), minute: date.getMinutes() }; var dateSpan = $("<abbr title='" + date.toISOString() + "' class='auxText'>" + toDisplayDateNoTime(dt) + "</abbr>"); var toolsDiv = $("<div></div>"); outerDiv.append(profLink); outerDiv.append(nameLink); outerDiv.append(commentPara); outerDiv.append(dateSpan); outerDiv.append(toolsDiv); } else { flog("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(); } }, itemsPerPage: 10, 'paginateFn': function(comments, config, container) { flog("paginateFn-102-standard", comments, config, container); var totalComments = comments.length; var itemsPerPage = config.itemsPerPage; if (totalComments > itemsPerPage) { 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 - itemsPerPage) + ')').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 - itemsPerPage - 1) + ')').show().removeClass('hidden-comment'); if (totalHiddenComments <= itemsPerPage) { $(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
