From ed700ef504bd2d4849e0b6f5db7aa7d90ec76e6f Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Sun, 8 May 2016 20:33:59 +0300 Subject: [PATCH] Fix unread counter not being formatted on page load --- client/js/libs/handlebars/roundBadgeNumber.js | 9 +++++++++ client/js/lounge.js | 4 ++-- client/views/chan.tpl | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) create mode 100644 client/js/libs/handlebars/roundBadgeNumber.js diff --git a/client/js/libs/handlebars/roundBadgeNumber.js b/client/js/libs/handlebars/roundBadgeNumber.js new file mode 100644 index 00000000..1a6ad031 --- /dev/null +++ b/client/js/libs/handlebars/roundBadgeNumber.js @@ -0,0 +1,9 @@ +Handlebars.registerHelper( + "roundBadgeNumber", function(count) { + if (count < 1000) { + return count; + } + + return (count / 1000).toFixed(2).slice(0, -1) + "k"; + } +); diff --git a/client/js/lounge.js b/client/js/lounge.js index de473868..41dd41a2 100644 --- a/client/js/lounge.js +++ b/client/js/lounge.js @@ -670,7 +670,7 @@ $(function() { self.addClass("active") .find(".badge") .removeClass("highlight") - .data("count", "") + .data("count", 0) .empty(); if (sidebar.find(".highlight").length === 0) { @@ -845,7 +845,7 @@ $(function() { if (badge.length !== 0) { var i = (badge.data("count") || 0) + 1; badge.data("count", i); - badge.html(i > 999 ? (i / 1000).toFixed(1) + "k" : i); + badge.html(Handlebars.helpers.roundBadgeNumber(i)); if (msg.highlight) { badge.addClass("highlight"); } diff --git a/client/views/chan.tpl b/client/views/chan.tpl index 47495362..22a6c3cc 100644 --- a/client/views/chan.tpl +++ b/client/views/chan.tpl @@ -1,6 +1,6 @@ {{#each channels}}
- {{#if unread}}{{unread}}{{/if}} + {{#if unread}}{{roundBadgeNumber unread}}{{/if}} {{name}}