From b1a6d394e301e73e12cc78e285dc7670f31b8344 Mon Sep 17 00:00:00 2001 From: barisusakli Date: Mon, 31 Mar 2014 14:43:44 -0400 Subject: [PATCH] moved format number functions to utils --- public/src/app.js | 19 +------------------ public/src/forum/account.js | 4 ++-- public/src/forum/accountposts.js | 2 +- public/src/forum/category.js | 2 +- public/src/forum/favourites.js | 4 ++-- public/src/forum/followers.js | 8 ++++---- public/src/forum/following.js | 2 +- public/src/forum/recent.js | 4 ++-- public/src/forum/topic.js | 6 +++--- public/src/forum/users.js | 2 +- public/src/utils.js | 17 +++++++++++++++++ 11 files changed, 35 insertions(+), 35 deletions(-) diff --git a/public/src/app.js b/public/src/app.js index 3d2b78c6bd..a2219dfe24 100644 --- a/public/src/app.js +++ b/public/src/app.js @@ -166,11 +166,6 @@ var socket, }); }; - // takes a string like 1000 and returns 1,000 - app.addCommas = function (text) { - return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); - }; - // use unique alert_id to have multiple alerts visible at a time, use the same alert_id to fade out the current instance // type : error, success, info, warning/notify // title = bolded title text @@ -362,12 +357,6 @@ var socket, }); }; - app.makeNumbersHumanReadable = function(elements) { - elements.each(function() { - $(this).html(utils.makeNumberHumanReadable($(this).attr('title'))); - }); - }; - app.processPage = function () { app.populateOnlineUsers(); @@ -376,7 +365,7 @@ var socket, $('span.timeago').timeago(); $('.post-content img').addClass('img-responsive'); - app.makeNumbersHumanReadable($('.human-readable-number')); + utils.makeNumbersHumanReadable($('.human-readable-number')); app.createUserTooltips(); @@ -407,12 +396,6 @@ var socket, } }; - app.addCommasToNumbers = function () { - $('.formatted-number').each(function (index, element) { - $(element).html(app.addCommas($(element).html())); - }); - }; - app.openChat = function (username, touid) { if (username === app.username) { app.alert({ diff --git a/public/src/forum/account.js b/public/src/forum/account.js index 9fbccf2bf7..ba5338448a 100644 --- a/public/src/forum/account.js +++ b/public/src/forum/account.js @@ -12,8 +12,8 @@ define(['forum/accountheader'], function(header) { var username = $('.account-username').html(); app.enterRoom('user/' + theirid); - app.addCommasToNumbers(); - app.makeNumbersHumanReadable($('.account .human-readable-number')); + utils.addCommasToNumbers($('.account .formatted-number')); + utils.makeNumbersHumanReadable($('.account .human-readable-number')); $('.user-recent-posts img').addClass('img-responsive'); var followBtn = $('#follow-btn'); diff --git a/public/src/forum/accountposts.js b/public/src/forum/accountposts.js index 1609886fa1..1403b606fe 100644 --- a/public/src/forum/accountposts.js +++ b/public/src/forum/accountposts.js @@ -49,7 +49,7 @@ define(['forum/accountheader'], function(header) { $('.user-favourite-posts').append(html); $('span.timeago').timeago(); app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + utils.makeNumbersHumanReadable(html.find('.human-readable-number')); }); }); } diff --git a/public/src/forum/category.js b/public/src/forum/category.js index f493df08ed..eef2a04207 100644 --- a/public/src/forum/category.js +++ b/public/src/forum/category.js @@ -284,7 +284,7 @@ define(['composer', 'forum/pagination'], function(composer, pagination) { html.find('span.timeago').timeago(); app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + utils.makeNumbersHumanReadable(html.find('.human-readable-number')); if (typeof callback === 'function') { callback(topics); diff --git a/public/src/forum/favourites.js b/public/src/forum/favourites.js index 6b992c89de..f9944e5e29 100644 --- a/public/src/forum/favourites.js +++ b/public/src/forum/favourites.js @@ -42,9 +42,9 @@ define(['forum/accountheader'], function(header) { html = $(translatedHTML); html.find('img').addClass('img-responsive'); $('.user-favourite-posts').append(html); - $('span.timeago').timeago(); + html.find('span.timeago').timeago(); app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + utils.makeNumbersHumanReadable(html.find('.human-readable-number')); }); }); } diff --git a/public/src/forum/followers.js b/public/src/forum/followers.js index 7916a67214..15263c142e 100644 --- a/public/src/forum/followers.js +++ b/public/src/forum/followers.js @@ -9,11 +9,11 @@ define(['forum/accountheader'], function(header) { followersCount = ajaxify.variables.get('followersCount'); - if (parseInt(followersCount, 10) === 0) { - $('#no-followers-notice').removeClass('hide'); - } + if (parseInt(followersCount, 10) === 0) { + $('#no-followers-notice').removeClass('hide'); + } - app.addCommasToNumbers(); + utils.addCommasToNumbers($('.account .formatted-number')); }; return Followers; diff --git a/public/src/forum/following.js b/public/src/forum/following.js index 4bc23d1a5a..80571cd19d 100644 --- a/public/src/forum/following.js +++ b/public/src/forum/following.js @@ -10,7 +10,7 @@ define(['forum/accountheader'], function(header) { $('#no-following-notice').removeClass('hide'); } - app.addCommasToNumbers(); + utils.addCommasToNumbers($('.account .formatted-number')); }; return Following; diff --git a/public/src/forum/recent.js b/public/src/forum/recent.js index 81f69f098b..17d5abedc8 100644 --- a/public/src/forum/recent.js +++ b/public/src/forum/recent.js @@ -124,9 +124,9 @@ define(function() { html = $(translatedHTML); $('#topics-container').append(html); - $('span.timeago').timeago(); + html.find('span.timeago').timeago(); app.createUserTooltips(); - app.makeNumbersHumanReadable(html.find('.human-readable-number')); + utils.makeNumbersHumanReadable(html.find('.human-readable-number')); }); }); } diff --git a/public/src/forum/topic.js b/public/src/forum/topic.js index 387c147b52..ba4e4ae41f 100644 --- a/public/src/forum/topic.js +++ b/public/src/forum/topic.js @@ -44,7 +44,7 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], } $(function() { - app.addCommasToNumbers(); + utils.addCommasToNumbers($('.topic .formatted-number')); app.enterRoom('topic_' + tid); @@ -761,8 +761,8 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'], app.populateOnlineUsers(); app.createUserTooltips(); - app.addCommasToNumbers(); - app.makeNumbersHumanReadable($('.human-readable-number')); + utils.addCommasToNumbers(html.find('.formatted-number')); + utils.makeNumbersHumanReadable(html.find('.human-readable-number')); html.find('span.timeago').timeago(); html.find('.post-content img').addClass('img-responsive'); updatePostCount(); diff --git a/public/src/forum/users.js b/public/src/forum/users.js index 4a74dacb7f..180bcd36fe 100644 --- a/public/src/forum/users.js +++ b/public/src/forum/users.js @@ -16,7 +16,7 @@ define(function() { var lastSearch = null; - app.addCommasToNumbers(); + utils.addCommasToNumbers($('.users .formatted-number')); $('.nav-pills li').removeClass('active'); $('.nav-pills li a').each(function() { diff --git a/public/src/utils.js b/public/src/utils.js index b62a8bce21..a66681c559 100644 --- a/public/src/utils.js +++ b/public/src/utils.js @@ -198,6 +198,12 @@ return (firstChar === '.' || firstChar === '/'); }, + makeNumbersHumanReadable: function(elements) { + elements.each(function() { + $(this).html(utils.makeNumberHumanReadable($(this).attr('title'))); + }); + }, + makeNumberHumanReadable: function(num) { var n = parseInt(num, 10); if(!n) { @@ -212,6 +218,17 @@ return n; }, + addCommasToNumbers: function (elements) { + elements.each(function (index, element) { + $(element).html(utils.addCommas($(element).html())); + }); + }, + + // takes a string like 1000 and returns 1,000 + addCommas: function (text) { + return text.replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,"); + }, + toISOString: function(timestamp) { if(!timestamp) { return '';