From a0c7e187f54ff3e401168c440e8e88779abd35b2 Mon Sep 17 00:00:00 2001 From: Baris Usakli Date: Wed, 16 Oct 2013 13:25:17 -0400 Subject: [PATCH] footer stats will display human readable stuff --- public/src/forum/footer.js | 9 ++++++--- public/src/utils.js | 9 +++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/public/src/forum/footer.js b/public/src/forum/footer.js index d3cc3d094f..31e96395df 100644 --- a/public/src/forum/footer.js +++ b/public/src/forum/footer.js @@ -7,13 +7,16 @@ socket.emit('user.count', {}); socket.on('user.count', function(data) { - stats_users.innerHTML = data.count; + stats_users.innerHTML = utils.makeNumberHumanReadable(data.count); + stats_users.title = data.count; }); socket.emit('post.stats'); socket.on('post.stats', function(data) { - stats_topics.innerHTML = data.topics; - stats_posts.innerHTML = data.posts; + stats_topics.innerHTML = utils.makeNumberHumanReadable(data.topics); + stats_topics.title = data.topics; + stats_posts.innerHTML = utils.makeNumberHumanReadable(data.posts); + stats_posts.title = data.posts; }); socket.emit('api:user.active.get'); diff --git a/public/src/utils.js b/public/src/utils.js index c6f586425e..c99fbb99a3 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -162,6 +162,15 @@ isRelativeUrl: function(url) { var firstChar = url.slice(0, 1); return (firstChar === '.' || firstChar === '/'); + }, + + makeNumberHumanReadable: function(num) { + num = parseInt(num, 10); + if (num > 999999) + return (num / 1000000).toFixed(1) + 'm'; + else if(num > 999) + return (num / 1000).toFixed(1) + 'k'; + return num; } }