Apply new structure in the section that shows the comments icon together with the number of comments so that it is easier to unify them into one component. Please note that we updated the comment-number class to comments-count in order to simplify the css in the new component in the next commit.
25 lines
1.1 KiB
Plaintext
25 lines
1.1 KiB
Plaintext
if ($(".comment").length == 0) {
|
|
$("#comments-box").append("<%= j render("comments_box", annotation: @annotation) %>").show();
|
|
} else {
|
|
$("#comments-box #comments").append("<%= j render("comments", annotation: @annotation) %>");
|
|
|
|
var current_annotation_link = $("#annotation-link a").attr("href")
|
|
var sub_annotation_ids = current_annotation_link.split("=")[1];
|
|
if (sub_annotation_ids.length == 0) {
|
|
var new_annotation_link = current_annotation_link + <%= "#{@annotation.id}" %>
|
|
}
|
|
else {
|
|
var new_annotation_link = current_annotation_link + "," + <%= "#{@annotation.id}" %>
|
|
}
|
|
|
|
$("#annotation-link a").attr("href", new_annotation_link)
|
|
|
|
var current_comment_text = $(".comments-count").text()
|
|
var current_comment_count = current_comment_text.match(/\d+/)[0]
|
|
var new_comment_count = parseInt(current_comment_count) + parseInt(<%= @annotation.comments.roots.count %>)
|
|
var new_comment_count_text = current_comment_text.replace(/(\d+)/, new_comment_count);
|
|
$(".comments-count").text(new_comment_count_text)
|
|
}
|
|
|
|
<%= render "comments_box_form", comment: @comment, annotation: @annotation %>
|