mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 14:05:46 +01:00
moved format number functions to utils
This commit is contained in:
@@ -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({
|
||||
|
||||
@@ -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');
|
||||
|
||||
@@ -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'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ define(['forum/accountheader'], function(header) {
|
||||
$('#no-followers-notice').removeClass('hide');
|
||||
}
|
||||
|
||||
app.addCommasToNumbers();
|
||||
utils.addCommasToNumbers($('.account .formatted-number'));
|
||||
};
|
||||
|
||||
return Followers;
|
||||
|
||||
@@ -10,7 +10,7 @@ define(['forum/accountheader'], function(header) {
|
||||
$('#no-following-notice').removeClass('hide');
|
||||
}
|
||||
|
||||
app.addCommasToNumbers();
|
||||
utils.addCommasToNumbers($('.account .formatted-number'));
|
||||
};
|
||||
|
||||
return Following;
|
||||
|
||||
@@ -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'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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() {
|
||||
|
||||
@@ -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 '';
|
||||
|
||||
Reference in New Issue
Block a user