mirror of
https://github.com/NodeBB/NodeBB.git
synced 2025-11-06 22:15:48 +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
|
// 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
|
// type : error, success, info, warning/notify
|
||||||
// title = bolded title text
|
// 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.processPage = function () {
|
||||||
app.populateOnlineUsers();
|
app.populateOnlineUsers();
|
||||||
|
|
||||||
@@ -376,7 +365,7 @@ var socket,
|
|||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
$('.post-content img').addClass('img-responsive');
|
$('.post-content img').addClass('img-responsive');
|
||||||
|
|
||||||
app.makeNumbersHumanReadable($('.human-readable-number'));
|
utils.makeNumbersHumanReadable($('.human-readable-number'));
|
||||||
|
|
||||||
app.createUserTooltips();
|
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) {
|
app.openChat = function (username, touid) {
|
||||||
if (username === app.username) {
|
if (username === app.username) {
|
||||||
app.alert({
|
app.alert({
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ define(['forum/accountheader'], function(header) {
|
|||||||
var username = $('.account-username').html();
|
var username = $('.account-username').html();
|
||||||
app.enterRoom('user/' + theirid);
|
app.enterRoom('user/' + theirid);
|
||||||
|
|
||||||
app.addCommasToNumbers();
|
utils.addCommasToNumbers($('.account .formatted-number'));
|
||||||
app.makeNumbersHumanReadable($('.account .human-readable-number'));
|
utils.makeNumbersHumanReadable($('.account .human-readable-number'));
|
||||||
$('.user-recent-posts img').addClass('img-responsive');
|
$('.user-recent-posts img').addClass('img-responsive');
|
||||||
|
|
||||||
var followBtn = $('#follow-btn');
|
var followBtn = $('#follow-btn');
|
||||||
|
|||||||
@@ -49,7 +49,7 @@ define(['forum/accountheader'], function(header) {
|
|||||||
$('.user-favourite-posts').append(html);
|
$('.user-favourite-posts').append(html);
|
||||||
$('span.timeago').timeago();
|
$('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
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();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
app.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
|
|
||||||
if (typeof callback === 'function') {
|
if (typeof callback === 'function') {
|
||||||
callback(topics);
|
callback(topics);
|
||||||
|
|||||||
@@ -42,9 +42,9 @@ define(['forum/accountheader'], function(header) {
|
|||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
html.find('img').addClass('img-responsive');
|
html.find('img').addClass('img-responsive');
|
||||||
$('.user-favourite-posts').append(html);
|
$('.user-favourite-posts').append(html);
|
||||||
$('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
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');
|
$('#no-followers-notice').removeClass('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
app.addCommasToNumbers();
|
utils.addCommasToNumbers($('.account .formatted-number'));
|
||||||
};
|
};
|
||||||
|
|
||||||
return Followers;
|
return Followers;
|
||||||
|
|||||||
@@ -10,7 +10,7 @@ define(['forum/accountheader'], function(header) {
|
|||||||
$('#no-following-notice').removeClass('hide');
|
$('#no-following-notice').removeClass('hide');
|
||||||
}
|
}
|
||||||
|
|
||||||
app.addCommasToNumbers();
|
utils.addCommasToNumbers($('.account .formatted-number'));
|
||||||
};
|
};
|
||||||
|
|
||||||
return Following;
|
return Following;
|
||||||
|
|||||||
@@ -124,9 +124,9 @@ define(function() {
|
|||||||
|
|
||||||
html = $(translatedHTML);
|
html = $(translatedHTML);
|
||||||
$('#topics-container').append(html);
|
$('#topics-container').append(html);
|
||||||
$('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
app.createUserTooltips();
|
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() {
|
$(function() {
|
||||||
app.addCommasToNumbers();
|
utils.addCommasToNumbers($('.topic .formatted-number'));
|
||||||
|
|
||||||
app.enterRoom('topic_' + tid);
|
app.enterRoom('topic_' + tid);
|
||||||
|
|
||||||
@@ -761,8 +761,8 @@ define(['forum/pagination', 'forum/topic/threadTools', 'forum/topic/postTools'],
|
|||||||
|
|
||||||
app.populateOnlineUsers();
|
app.populateOnlineUsers();
|
||||||
app.createUserTooltips();
|
app.createUserTooltips();
|
||||||
app.addCommasToNumbers();
|
utils.addCommasToNumbers(html.find('.formatted-number'));
|
||||||
app.makeNumbersHumanReadable($('.human-readable-number'));
|
utils.makeNumbersHumanReadable(html.find('.human-readable-number'));
|
||||||
html.find('span.timeago').timeago();
|
html.find('span.timeago').timeago();
|
||||||
html.find('.post-content img').addClass('img-responsive');
|
html.find('.post-content img').addClass('img-responsive');
|
||||||
updatePostCount();
|
updatePostCount();
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ define(function() {
|
|||||||
|
|
||||||
var lastSearch = null;
|
var lastSearch = null;
|
||||||
|
|
||||||
app.addCommasToNumbers();
|
utils.addCommasToNumbers($('.users .formatted-number'));
|
||||||
|
|
||||||
$('.nav-pills li').removeClass('active');
|
$('.nav-pills li').removeClass('active');
|
||||||
$('.nav-pills li a').each(function() {
|
$('.nav-pills li a').each(function() {
|
||||||
|
|||||||
@@ -198,6 +198,12 @@
|
|||||||
return (firstChar === '.' || firstChar === '/');
|
return (firstChar === '.' || firstChar === '/');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
makeNumbersHumanReadable: function(elements) {
|
||||||
|
elements.each(function() {
|
||||||
|
$(this).html(utils.makeNumberHumanReadable($(this).attr('title')));
|
||||||
|
});
|
||||||
|
},
|
||||||
|
|
||||||
makeNumberHumanReadable: function(num) {
|
makeNumberHumanReadable: function(num) {
|
||||||
var n = parseInt(num, 10);
|
var n = parseInt(num, 10);
|
||||||
if(!n) {
|
if(!n) {
|
||||||
@@ -212,6 +218,17 @@
|
|||||||
return n;
|
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) {
|
toISOString: function(timestamp) {
|
||||||
if(!timestamp) {
|
if(!timestamp) {
|
||||||
return '';
|
return '';
|
||||||
|
|||||||
Reference in New Issue
Block a user