summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/header.js
blob: ea2e2205077c4f6d35cc301fe59670c0bb5d3766 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
import { highCountTrim } from '~/lib/utils/text_utility';

/**
 * Updates todo counter when todos are toggled.
 * When count is 0, we hide the badge.
 *
 * @param {jQuery.Event} e
 * @param {String} count
 */
$(document).on('todo:toggle', (e, count) => {
  const parsedCount = parseInt(count, 10);
  const $todoPendingCount = $('.todos-count');

  $todoPendingCount.text(highCountTrim(parsedCount));
  $todoPendingCount.toggleClass('hidden', parsedCount === 0);
});