Skip to content

Commit

Permalink
Added events for upload progress tracking
Browse files Browse the repository at this point in the history
  • Loading branch information
lorenzos committed Jul 4, 2012
1 parent 9b21371 commit aa572b5
Showing 1 changed file with 18 additions and 5 deletions.
23 changes: 18 additions & 5 deletions Source/MooUpload.js
Expand Up @@ -120,10 +120,12 @@ var MooUpload = new Class({
onAddFiles: function(){}, onAddFiles: function(){},
onBeforeUpload: function(){}, onBeforeUpload: function(){},
onFileDelete: function(fileindex){}, onFileDelete: function(fileindex){},
onFileProgress: function(fileindex, percent){},
onFileUpload: function(fileindex, response){}, onFileUpload: function(fileindex, response){},
onFileUploadError: function(fileindex, response){}, onFileUploadError: function(fileindex, response){},
onFinishUpload: function(){}, onFinishUpload: function(){},
onLoad: function(){}, onLoad: function(){},
onProgress: function(percent, stats){},
onSelect: function(){}, onSelect: function(){},
onSelectError: function(error, filename, filesize){} onSelectError: function(error, filename, filesize){}
}, },
Expand Down Expand Up @@ -431,8 +433,12 @@ var MooUpload = new Class({
this.uploading = false; this.uploading = false;
progress.removeClass('mooupload_on'); progress.removeClass('mooupload_on');
progress.addClass('mooupload_off'); progress.addClass('mooupload_off');

this.fireEvent('onProgress', [100, stats]);
this.fireEvent('onFinishUpload'); this.fireEvent('onFinishUpload');
}
else
{
this.fireEvent('onProgress', [percent, stats]);
} }


}, },
Expand Down Expand Up @@ -763,6 +769,8 @@ var MooUpload = new Class({


fileProgress: function (file) { fileProgress: function (file) {


this.fireEvent('onFileProgress', [file[0].id, file[0].progress.percentLoaded]);

if (this.options.listview) if (this.options.listview)
{ {
var respcontainer = document.id(subcontainer_id+'_file_' + file[0].id); var respcontainer = document.id(subcontainer_id+'_file_' + file[0].id);
Expand All @@ -776,6 +784,8 @@ var MooUpload = new Class({


this.filelist[file[0].id - 1].uploaded = true; this.filelist[file[0].id - 1].uploaded = true;


this.fireEvent('onFileProgress', [file[0].id, 100]);

if (this.options.listview) if (this.options.listview)
{ {


Expand Down Expand Up @@ -1010,17 +1020,20 @@ var MooUpload = new Class({


if (total < file.size) if (total < file.size)
{ {

var percent = (total / file.size) * 100;
this.fireEvent('onFileProgress', [filenum, percent]);

if (this.options.listview) if (this.options.listview)
{ {
var percent = (total / file.size) * 100;
respcontainer.set('html', percent.ceil()+'%'); respcontainer.set('html', percent.ceil()+'%');
} }


this.html5send(subcontainer, file_id, file, start + response.size.toInt(), filenum, true) // Recursive upload this.html5send(subcontainer, file_id, file, start + response.size.toInt(), filenum, true) // Recursive upload
} }
else else
{ {
this.fireEvent('onFileProgress', [filenum, 100]);

if (this.options.listview) if (this.options.listview)
{ {
respcontainer.addClass('mooupload_noerror'); respcontainer.addClass('mooupload_noerror');
Expand Down

0 comments on commit aa572b5

Please sign in to comment.