From e1e658c6547a2b00a2b5b32bf3cd34ab8a5f2a52 Mon Sep 17 00:00:00 2001 From: Florian Pritz Date: Thu, 17 Jan 2013 18:54:35 +0100 Subject: Support multiple uploads in the same request This change *should* be backwards compatible. Signed-off-by: Florian Pritz --- data/js/script.js | 26 +++++++++++++++++--------- 1 file changed, 17 insertions(+), 9 deletions(-) (limited to 'data') diff --git a/data/js/script.js b/data/js/script.js index 4df973296..cb9afa66c 100644 --- a/data/js/script.js +++ b/data/js/script.js @@ -74,17 +74,25 @@ function fixedEncodeURIComponent (str) { // check file size before uploading if browser support html5 if (window.File && window.FileList) { function checkFileUpload(evt) { - var f = evt.target.files[0]; - if (f.size > max_upload_size) { - document.getElementById('upload_button').innerHTML = "File too big"; - document.getElementById('upload_button').disabled = true; - } else { - document.getElementById('upload_button').innerHTML = "Upload it!"; - document.getElementById('upload_button').disabled = false; - } + var sum = 0; + var files = evt.target.files; + + // TODO: check all forms, not only the one we are called from + for (var i = 0; i < files.length; i++) { + var f = evt.target.files[i]; + sum += f.size; + } + + if (sum > max_upload_size) { + document.getElementById('upload_button').innerHTML = "File(s) too big"; + document.getElementById('upload_button').disabled = true; + } else { + document.getElementById('upload_button').innerHTML = "Upload it!"; + document.getElementById('upload_button').disabled = false; + } } - $('#file').bind('change', checkFileUpload); + $('.file-upload').bind('change', checkFileUpload); } }); -- cgit v1.2.3-24-g4f1b