From 090bb3866afb0f8e347ab5c3b9c1fba41f4d2255 Mon Sep 17 00:00:00 2001 From: Devaev Maxim Date: Sun, 10 Nov 2019 00:59:27 +0300 Subject: otg msd ui --- web/share/js/tools.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) (limited to 'web/share/js/tools.js') diff --git a/web/share/js/tools.js b/web/share/js/tools.js index f249de33..8212b62f 100644 --- a/web/share/js/tools.js +++ b/web/share/js/tools.js @@ -55,6 +55,15 @@ export var tools = new function() { return id; }; + this.formatSize = function(size) { + if (size > 0) { + let index = Math.floor( Math.log(size) / Math.log(1024) ); + return (size / Math.pow(1024, index)).toFixed(2) * 1 + " " + ["B", "KiB", "MiB", "GiB", "TiB"][index]; + } else { + return 0; + } + }; + /************************************************************************/ this.getCookie = function(name) { @@ -110,6 +119,11 @@ export var tools = new function() { }; }; + this.setProgressPercent = function(el, title, percent) { + el.setAttribute("data-label", title); + $(`${el.id}-value`).style.width = `${percent}%`; + }; + /************************************************************************/ let __debug = (new URL(window.location.href)).searchParams.get("debug"); -- cgit v1.2.3