Browse Source

Upgrade to release v4.1.3

Kartik Visweswaran 10 years ago
parent
commit
37872f94d5
3 changed files with 14 additions and 9 deletions
  1. 2 1
      CHANGE.md
  2. 12 8
      js/fileinput.js
  3. 0 0
      js/fileinput.min.js

+ 2 - 1
CHANGE.md

@@ -10,7 +10,8 @@ version 4.1.3
     - `filebatchuploadsuccess`
     - `filebatchuploadcomplete`
 2. (enh #86): Disable thumbnail action buttons when upload is in progress.
-    
+3. (enh #87): More correct progress indicator percentage for asynchronous upload.
+
 version 4.1.2
 =============
 **Date:** 19-Dec-2014

+ 12 - 8
js/fileinput.js

@@ -817,30 +817,31 @@
             });
         },
         initXhr: function(xhrobj) {
-            var self = this;
+            var self = this, factor = arguments.length > 1 ? (self.uploadCount + 1) * 100/arguments[1] : 98;
             if (xhrobj.upload) {
                 xhrobj.upload.addEventListener('progress', function(event) {
                     var pct = 0, position = event.loaded || event.position, total = event.total;
                     if (event.lengthComputable) {
-                        pct = Math.ceil(position / total * 98);
+                        pct = Math.ceil(position / total * factor);
                     }
                     self.uploadPercent = Math.max(pct, self.uploadPercent);
-                    //Set progress
                     self.setProgress(self.uploadPercent);
                 }, false);
             }
             return xhrobj;
         },
         upload: function(i) {
-            var self = this, files = self.getFileStack(), formdata = new FormData(),
+            var self = this, files = self.getFileStack(), total = files.length, formdata = new FormData(), 
                 previewId = self.previewInitId + "-" + i, $thumb = $('#' + previewId), 
                 $btnUpload = $thumb.find('.kv-file-upload'), $btnDelete = $thumb.find('.kv-file-remove'),
                 $indicator = $thumb.find('.file-upload-indicator'), config = self.fileActionSettings;
+            if (total == 0) {
+                return;
+            }
             if ($btnUpload.hasClass('disabled')) {
                 return;
             }
             var percent,
-                total = files.length,
                 allFiles = arguments.length > 1,
                 setIndicator = function (icon, msg) {
                     $indicator.html(config[icon]);
@@ -872,7 +873,7 @@
             self.ajaxRequests.push($.ajax({
                 xhr: function() {
                     var xhrobj = $.ajaxSettings.xhr();
-                    return self.initXhr(xhrobj);
+                    return self.initXhr(xhrobj, self.getFileStack().length);
                 },
                 url: self.uploadUrl,
                 type: 'POST',
@@ -933,8 +934,11 @@
             }));
         },
         uploadBatch: function() {
-            var self = this, files = self.filestack, total = files.length, 
-                config = self.fileActionSettings; formdata = new FormData(),
+            var self = this, files = self.filestack, total = files.length;
+            if (total == 0) {
+                return;
+            }
+            var config = self.fileActionSettings; formdata = new FormData(),
                 setIndicator = function (i, icon, msg) {
                     var $indicator = $('#' + self.previewInitId + "-" + i).find('.file-upload-indicator');
                     $indicator.html(config[icon]);

File diff suppressed because it is too large
+ 0 - 0
js/fileinput.min.js


Some files were not shown because too many files changed in this diff