diff options
author | Morris Jobke <hey@morrisjobke.de> | 2014-06-02 17:37:53 +0200 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2014-06-02 17:37:53 +0200 |
commit | dd8b7b7af892f16926d0b64bffa59cf616076144 (patch) | |
tree | cc5c300749dcac85a01ae3f6ae89ef902958ca3c /core/js/js.js | |
parent | 51602f67e002dc23342fd7c13d803a98b732e812 (diff) | |
parent | 5d457dafc1d8a2aafb0d630a7f8a5b56cef7d97b (diff) | |
download | nextcloud-server-dd8b7b7af892f16926d0b64bffa59cf616076144.tar.gz nextcloud-server-dd8b7b7af892f16926d0b64bffa59cf616076144.zip |
Merge pull request #8613 from owncloud/filesize-alignment
Improve aligment of file size
Diffstat (limited to 'core/js/js.js')
-rw-r--r-- | core/js/js.js | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/core/js/js.js b/core/js/js.js index 21a2d4c1b35..a859034ed01 100644 --- a/core/js/js.js +++ b/core/js/js.js @@ -1163,9 +1163,10 @@ $.fn.filterAttr = function(attr_name, attr_value) { /** * Returns a human readable file size * @param {number} size Size in bytes + * @param {boolean} skipSmallSizes return '< 1 kB' for small files * @return {string} */ -function humanFileSize(size) { +function humanFileSize(size, skipSmallSizes) { var humanList = ['B', 'kB', 'MB', 'GB', 'TB']; // Calculate Log with base 1024: size = 1024 ** order var order = size?Math.floor(Math.log(size) / Math.log(1024)):0; @@ -1173,6 +1174,13 @@ function humanFileSize(size) { order = Math.min(humanList.length - 1, order); var readableFormat = humanList[order]; var relativeSize = (size / Math.pow(1024, order)).toFixed(1); + if(skipSmallSizes === true && order === 0) { + if(relativeSize !== "0.0"){ + return '< 1 kB'; + } else { + return '0 kB'; + } + } if(order < 2){ relativeSize = parseFloat(relativeSize).toFixed(0); } |