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}}