LPology / Simple-Ajax-Uploader

Javascript file upload plugin with progress bar support. Works in all major browsers, including IE7+, Chrome, Firefox, Safari, and Opera. No dependencies - use it with or without jQuery.
995 stars 268 forks source link

raise event for invalid size or file type rather than hard coded alert #8

Closed devtrends closed 11 years ago

devtrends commented 11 years ago

would be nice if event was raised instead passing through filename. then could handle any way we like.

LPology commented 11 years ago

I like this idea. Do you mean creating a custom event, or adding callback functions like onSizeError() and onExtError() for handling those situations?

Adding callback functions is super easy - 4 lines of code total. I added a branch "develop" and changed the demo to use the callbacks (it has the same behavior with the alerts because I'm manually calling _errorMsg() but you could obv do anything).

Here's the code from the demo:

onExtError: function(filename, extension) { 
  this._errorMsg('ext');
},
onSizeError: function(filename, fileSize) {
  this._errorMsg('size');
}, 

An added bonus is that _errorMsg() can be removed, resulting in 29 fewer lines of code.

Thoughts?