moved format number functions to utils

v1.18.x
barisusakli 11 years ago
parent f01cb88c57
commit b1a6d394e3

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

@ -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;

@ -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 '';

Loading…
Cancel
Save