diff options
author | Florian Pritz <bluewind@xinu.at> | 2013-01-17 18:54:35 +0100 |
---|---|---|
committer | Florian Pritz <bluewind@xinu.at> | 2013-01-17 21:25:44 +0100 |
commit | e1e658c6547a2b00a2b5b32bf3cd34ab8a5f2a52 (patch) | |
tree | f26e9ef785ff1d2f8d23b7235fb991e93d5e6d1c /data/js | |
parent | dc3afcb35744ec5d9036fc329dab25f0c8dcd7a5 (diff) |
Support multiple uploads in the same request
This change *should* be backwards compatible.
Signed-off-by: Florian Pritz <bluewind@xinu.at>
Diffstat (limited to 'data/js')
-rw-r--r-- | data/js/script.js | 26 |
1 files changed, 17 insertions, 9 deletions
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); } }); |