mirror of
https://github.com/NodeBB/NodeBB.git
synced 2026-01-22 15:33:13 +01:00
feat: allow changing fixed param
This commit is contained in:
@@ -439,15 +439,15 @@ const utils = {
|
||||
return !utils.isAbsoluteUrl(url);
|
||||
},
|
||||
|
||||
makeNumberHumanReadable: function (num) {
|
||||
makeNumberHumanReadable: function (num, toFixed = 1) {
|
||||
const n = parseInt(num, 10);
|
||||
if (!n) {
|
||||
return num;
|
||||
}
|
||||
if (n > 999999) {
|
||||
return (n / 1000000).toFixed(1) + 'm';
|
||||
return (n / 1000000).toFixed(toFixed) + 'm';
|
||||
} else if (n > 999) {
|
||||
return (n / 1000).toFixed(1) + 'k';
|
||||
return (n / 1000).toFixed(toFixed) + 'k';
|
||||
}
|
||||
return n;
|
||||
},
|
||||
|
||||
@@ -17,8 +17,9 @@ utils.getLanguage = function () {
|
||||
|
||||
utils.makeNumbersHumanReadable = function (elements) {
|
||||
elements.each(function () {
|
||||
$(this)
|
||||
.html(utils.makeNumberHumanReadable($(this).attr('title')))
|
||||
const $this = $(this);
|
||||
const toFixed = $this.attr('data-toFixed') || 1;
|
||||
$this.html(utils.makeNumberHumanReadable($(this).attr('title'), toFixed))
|
||||
.removeClass('hidden');
|
||||
});
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user