Merge pull request #308 from thelounge/xpaw/fix-badge-format

Fix unread counter not being formatted on page load
This commit is contained in:
Jérémie Astori 2016-05-09 00:07:36 -04:00
commit dc6c36401b
3 changed files with 12 additions and 3 deletions

View file

@ -0,0 +1,9 @@
Handlebars.registerHelper(
"roundBadgeNumber", function(count) {
if (count < 1000) {
return count;
}
return (count / 1000).toFixed(2).slice(0, -1) + "k";
}
);

View file

@ -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");
}

View file

@ -1,6 +1,6 @@
{{#each channels}}
<div data-id="{{id}}" data-target="#chan-{{id}}" data-title="{{name}}" class="chan {{type}}">
<span class="badge{{#if highlight}} highlight{{/if}}" data-count="{{unread}}">{{#if unread}}{{unread}}{{/if}}</span>
<span class="badge{{#if highlight}} highlight{{/if}}" data-count="{{unread}}">{{#if unread}}{{roundBadgeNumber unread}}{{/if}}</span>
<button class="close" aria-label="Close"></button>
<span class="name" title="{{name}}">{{name}}</span>
</div>