From ab24f5a292d4bfc186a719e555aaf55594ee80c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Guillaume=20Perr=C3=A9al?= <guillaume.perreal@irstea.fr> Date: Wed, 28 Jan 2015 15:17:32 +0100 Subject: [PATCH] =?UTF-8?q?js:=20v=C3=A9rifie=20l'attribut=20'data-size-pr?= =?UTF-8?q?ecision'=20pour=20formatter=20les=20tailles.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Resources/js/widget/file_upload.js | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/Resources/js/widget/file_upload.js b/Resources/js/widget/file_upload.js index c93c531c..7f5fed04 100644 --- a/Resources/js/widget/file_upload.js +++ b/Resources/js/widget/file_upload.js @@ -4,15 +4,18 @@ */ (function($) { - var formatFileSize = function(size) { + var formatFileSize = function(size, precision) { + if(typeof(precision) === "undefined") { + precision = 2; + } if(size > 1000000000) { - return (size/1000000000).toFixed(2) + ' Gio'; + return (size/1000000000).toFixed(precision) + ' Gio'; } if(size > 1000000) { - return (size/1000000).toFixed(2) + ' Mio'; + return (size/1000000).toFixed(precision) + ' Mio'; } if(size > 1000) { - return (size/1000).toFixed(2)+ ' Kio'; + return (size/1000).toFixed(precision)+ ' Kio'; } return size + ' o'; }, @@ -56,8 +59,8 @@ $button.toggle(options.multiple || !hasEntry); }; - $this.find('.template-download .size').each(function() { - $(this).text(formatFileSize($(this).text())); + $this.find('.size').each(function() { + $(this).text(formatFileSize($(this).text(), $(this).data('size-precision'))); }); updateDisplay(); -- GitLab