Skip to content

Commit 16b3d7a

Browse files
committed
* temporary fix for progress event
1 parent 943c9b7 commit 16b3d7a

File tree

6 files changed

+24
-16
lines changed

6 files changed

+24
-16
lines changed

dist/FileAPI.html5.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@
10511051
});
10521052

10531053
// Set upload status props
1054-
proxyXHR.total = _total;
1054+
proxyXHR.total = _total = (_total || 1);
10551055
proxyXHR.loaded = 0;
10561056
proxyXHR.filesLeft = dataArray.length;
10571057

@@ -1086,6 +1086,7 @@
10861086

10871087
_this._getFormData(_fileOptions, data, function (form){
10881088
if( !_loaded ){
1089+
data.size = data.size || 1;
10891090
// emit "upload" event
10901091
options.upload(proxyXHR, options);
10911092
}
@@ -1116,19 +1117,20 @@
11161117
} : noop,
11171118

11181119
complete: function (err){
1119-
// fixed throttle event
1120-
_fileLoaded = true;
1121-
11221120
_each(_xhrPropsExport, function (name){
11231121
proxyXHR[name] = xhr[name];
11241122
});
11251123

11261124
if( _file ){
1125+
data.total = (data.total || data.size);
11271126
data.loaded = data.total;
11281127

11291128
// emulate 100% "progress"
11301129
this.progress(data);
11311130

1131+
// fixed throttle event
1132+
_fileLoaded = true;
1133+
11321134
// bytes loaded
11331135
_loaded += data.size; // data.size != data.total, it's desirable fix this
11341136
proxyXHR.loaded = _loaded;

dist/FileAPI.html5.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/FileAPI.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1051,7 +1051,7 @@
10511051
});
10521052

10531053
// Set upload status props
1054-
proxyXHR.total = _total;
1054+
proxyXHR.total = _total = (_total || 1);
10551055
proxyXHR.loaded = 0;
10561056
proxyXHR.filesLeft = dataArray.length;
10571057

@@ -1086,6 +1086,7 @@
10861086

10871087
_this._getFormData(_fileOptions, data, function (form){
10881088
if( !_loaded ){
1089+
data.size = data.size || 1;
10891090
// emit "upload" event
10901091
options.upload(proxyXHR, options);
10911092
}
@@ -1116,19 +1117,20 @@
11161117
} : noop,
11171118

11181119
complete: function (err){
1119-
// fixed throttle event
1120-
_fileLoaded = true;
1121-
11221120
_each(_xhrPropsExport, function (name){
11231121
proxyXHR[name] = xhr[name];
11241122
});
11251123

11261124
if( _file ){
1125+
data.total = (data.total || data.size);
11271126
data.loaded = data.total;
11281127

11291128
// emulate 100% "progress"
11301129
this.progress(data);
11311130

1131+
// fixed throttle event
1132+
_fileLoaded = true;
1133+
11321134
// bytes loaded
11331135
_loaded += data.size; // data.size != data.total, it's desirable fix this
11341136
proxyXHR.loaded = _loaded;

dist/FileAPI.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

lib/FileAPI.core.js

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -957,7 +957,7 @@
957957
});
958958

959959
// Set upload status props
960-
proxyXHR.total = _total;
960+
proxyXHR.total = _total = (_total || 1);
961961
proxyXHR.loaded = 0;
962962
proxyXHR.filesLeft = dataArray.length;
963963

@@ -992,6 +992,7 @@
992992

993993
_this._getFormData(_fileOptions, data, function (form){
994994
if( !_loaded ){
995+
data.size = data.size || 1;
995996
// emit "upload" event
996997
options.upload(proxyXHR, options);
997998
}
@@ -1022,19 +1023,20 @@
10221023
} : noop,
10231024

10241025
complete: function (err){
1025-
// fixed throttle event
1026-
_fileLoaded = true;
1027-
10281026
_each(_xhrPropsExport, function (name){
10291027
proxyXHR[name] = xhr[name];
10301028
});
10311029

10321030
if( _file ){
1031+
data.total = (data.total || data.size);
10331032
data.loaded = data.total;
10341033

10351034
// emulate 100% "progress"
10361035
this.progress(data);
10371036

1037+
// fixed throttle event
1038+
_fileLoaded = true;
1039+
10381040
// bytes loaded
10391041
_loaded += data.size; // data.size != data.total, it's desirable fix this
10401042
proxyXHR.loaded = _loaded;

tests/tests.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -398,21 +398,23 @@ module('FileAPI');
398398
FileAPI.html5 && test('upload FileAPI.Image', function (){
399399
var file = FileAPI.getFiles(uploadForm['dino.png'])[0];
400400
var image = FileAPI.Image(file).rotate(90).preview(100);
401-
var _progressFail = false;
401+
var _progressFail = false, _progress = false;
402402

403403
stop();
404404
FileAPI.upload({
405405
url: 'http://rubaxa.org/FileAPI/server/ctrl.php',
406406
headers: { 'x-foo': 'bar' },
407407
files: { image: image },
408408
progress: function (evt){
409+
_progress = true;
409410
_progressFail = _progressFail || _checkProgressEvent(evt);
410411
},
411412
complete: function (err, res){
412413
var res = FileAPI.parseJSON(res.responseText);
413414

415+
ok(_progress, 'progress event');
414416
equal(res.data.HEADERS['X-Foo'], 'bar', 'X-Foo');
415-
417+
416418
imageEqual(res.images.image.dataURL, 'files/samples/'+browser+'-dino-90deg-100x100.png?1', 'dino 90deg 100x100', function (){
417419
start();
418420
});

0 commit comments

Comments
 (0)