From 57ef9573f28f21d4ede72d993ebd08f1c440b124 Mon Sep 17 00:00:00 2001 From: Anton Ignatov Date: Fri, 21 Jun 2019 10:43:41 +0200 Subject: [PATCH] Fix comments counter for zero comments --- app/assets/javascripts/sitewide/comments.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/app/assets/javascripts/sitewide/comments.js b/app/assets/javascripts/sitewide/comments.js index 415fa2fef..ecd1f0a83 100644 --- a/app/assets/javascripts/sitewide/comments.js +++ b/app/assets/javascripts/sitewide/comments.js @@ -2,8 +2,14 @@ /* eslint-disable no-restricted-globals, no-alert */ var Comments = (function() { function changeCounter(comment, value) { - var currnetCount = $('#comment-counter-' + comment.closest('.comments-container').attr('data-object-id')); - currnetCount.html(parseInt(currnetCount.html(), 10) + value); + var currentCount = $('#comment-counter-' + comment.closest('.comments-container').attr('data-object-id')); + var newValue = parseInt(currentCount.html(), 10) + value; + currentCount.html(newValue); + if (newValue === 0) { + currentCount.addClass('hidden'); + } else { + currentCount.removeClass('hidden'); + } } function scrollBottom(container) {