2018-03-09 15:18:59 -05:00
|
|
|
import $ from 'jquery';
|
2017-10-10 03:47:42 -04:00
|
|
|
import { highCountTrim } from '~/lib/utils/text_utility';
|
2017-03-11 02:30:44 -05:00
|
|
|
|
2017-10-10 03:47:42 -04:00
|
|
|
/**
|
|
|
|
* Updates todo counter when todos are toggled.
|
|
|
|
* When count is 0, we hide the badge.
|
|
|
|
*
|
|
|
|
* @param {jQuery.Event} e
|
|
|
|
* @param {String} count
|
|
|
|
*/
|
2017-10-30 14:59:16 -04:00
|
|
|
export default function initTodoToggle() {
|
|
|
|
$(document).on('todo:toggle', (e, count) => {
|
|
|
|
const parsedCount = parseInt(count, 10);
|
|
|
|
const $todoPendingCount = $('.todos-count');
|
2017-10-10 03:47:42 -04:00
|
|
|
|
2017-10-30 14:59:16 -04:00
|
|
|
$todoPendingCount.text(highCountTrim(parsedCount));
|
|
|
|
$todoPendingCount.toggleClass('hidden', parsedCount === 0);
|
|
|
|
});
|
|
|
|
}
|