From 2b8579e8b7ba29f3b53b7a6447c1ac1b46961485 Mon Sep 17 00:00:00 2001 From: ansuz Date: Tue, 18 Apr 2017 15:44:15 +0200 Subject: [PATCH] add pretty-printers for byte-counts --- www/common/common-util.js | 8 ++++++++ www/common/cryptpad-common.js | 2 ++ www/settings/main.js | 6 +----- 3 files changed, 11 insertions(+), 5 deletions(-) diff --git a/www/common/common-util.js b/www/common/common-util.js index 29b25c4fb..5b54f5381 100644 --- a/www/common/common-util.js +++ b/www/common/common-util.js @@ -81,5 +81,13 @@ define([], function () { .replace(/_+/g, '_'); }; + var bytesToMegabytes = Util.bytesToMegabytes = function (bytes) { + return Math.floor((bytes / (1024 * 1024) * 100)) / 100; + }; + + var bytesToKilobytes = Util.bytesToKilobytes = function (bytes) { + return Math.floor(bytes / 1024 * 100) / 100; + }; + return Util; }); diff --git a/www/common/cryptpad-common.js b/www/common/cryptpad-common.js index 36d045407..ffb6936c5 100644 --- a/www/common/cryptpad-common.js +++ b/www/common/cryptpad-common.js @@ -63,6 +63,8 @@ define([ var replaceHash = common.replaceHash = Util.replaceHash; var getHash = common.getHash = Util.getHash; var fixFileName = common.fixFileName = Util.fixFileName; + common.bytesToMegabytes = Util.bytesToMegabytes; + common.bytesToKilobytes = Util.bytesToKilobytes; // import hash utilities for export var createRandomHash = common.createRandomHash = Hash.createRandomHash; diff --git a/www/settings/main.js b/www/settings/main.js index 8600dba4d..0d66b7886 100644 --- a/www/settings/main.js +++ b/www/settings/main.js @@ -226,10 +226,6 @@ define([ return $div; }; - var bytesToMegabytes = function (bytes) { - return Math.floor((bytes / (1024 * 1024) * 100)) / 100; - }; - var createUsageButton = function (obj) { var proxy = obj.proxy; @@ -252,7 +248,7 @@ define([ Cryptpad.alert(Messages.settings_pinningError); return; } - Cryptpad.alert(Messages._getKey('settings_usageAmount', [bytesToMegabytes(bytes)])); + Cryptpad.alert(Messages._getKey('settings_usageAmount', [Cryptpad.bytesToMegabytes(bytes)])); }); }) .appendTo($div);