Permalink
Browse files

Added events for upload progress tracking

  • Loading branch information...
1 parent 9b21371 commit aa572b5f494020f9777633fd2e28eb15b33a8afb @lorenzos committed Jul 4, 2012
Showing with 18 additions and 5 deletions.
  1. +18 −5 Source/MooUpload.js
View
@@ -120,10 +120,12 @@ var MooUpload = new Class({
onAddFiles: function(){},
onBeforeUpload: function(){},
onFileDelete: function(fileindex){},
+ onFileProgress: function(fileindex, percent){},
onFileUpload: function(fileindex, response){},
onFileUploadError: function(fileindex, response){},
- onFinishUpload: function(){},
- onLoad: function(){},
+ onFinishUpload: function(){},
+ onLoad: function(){},
+ onProgress: function(percent, stats){},
onSelect: function(){},
onSelectError: function(error, filename, filesize){}
},
@@ -431,8 +433,12 @@ var MooUpload = new Class({
this.uploading = false;
progress.removeClass('mooupload_on');
progress.addClass('mooupload_off');
-
+ this.fireEvent('onProgress', [100, stats]);
this.fireEvent('onFinishUpload');
+ }
+ else
+ {
+ this.fireEvent('onProgress', [percent, stats]);
}
},
@@ -763,6 +769,8 @@ var MooUpload = new Class({
fileProgress: function (file) {
+ this.fireEvent('onFileProgress', [file[0].id, file[0].progress.percentLoaded]);
+
if (this.options.listview)
{
var respcontainer = document.id(subcontainer_id+'_file_' + file[0].id);
@@ -776,6 +784,8 @@ var MooUpload = new Class({
this.filelist[file[0].id - 1].uploaded = true;
+ this.fireEvent('onFileProgress', [file[0].id, 100]);
+
if (this.options.listview)
{
@@ -1010,17 +1020,20 @@ var MooUpload = new Class({
if (total < file.size)
{
-
+ var percent = (total / file.size) * 100;
+ this.fireEvent('onFileProgress', [filenum, percent]);
+
if (this.options.listview)
{
- var percent = (total / file.size) * 100;
respcontainer.set('html', percent.ceil()+'%');
}
this.html5send(subcontainer, file_id, file, start + response.size.toInt(), filenum, true) // Recursive upload
}
else
{
+ this.fireEvent('onFileProgress', [filenum, 100]);
+
if (this.options.listview)
{
respcontainer.addClass('mooupload_noerror');

0 comments on commit aa572b5

Please sign in to comment.