Created
August 11, 2012 12:49
-
-
Save pamelafox-coursera/3324242 to your computer and use it in GitHub Desktop.
Transloadit checkFileTypes
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// My HTML specifies accept="" on the input | |
// I add this additional function to transloadit2.js | |
Uploader.prototype.checkFileTypes = function() { | |
var self = this; | |
var acceptedTypes = self.$files.attr('accept'); | |
if (!acceptedTypes) { | |
return true; | |
} | |
acceptedTypes = acceptedTypes.split(','); | |
self.$files = self.$files.filter(function() { | |
var fileExt = this.value.split('.').pop().toLowerCase(); | |
for (var i = 0; i < acceptedTypes.length; i++) { | |
if (fileExt == acceptedTypes[i].split('/')[1]) { | |
return true; | |
} | |
} | |
self._options.onError('Sorry, we don\'t accept ' + fileExt + ' files.'); | |
return false; | |
}); | |
}; | |
// I modified my init a bit | |
Uploader.prototype.init = function($form, options) { | |
this.$form = $form; | |
this.options($.extend({}, OPTIONS, options || {})); | |
var self = this; | |
$form.find('input[type="file"]').on('change', function() { | |
self.validate(); | |
self.detectFileInputs(); | |
self.checkFileTypes(); | |
if (!self._options['processZeroFiles'] && self.$files.length === 0) { | |
self.submitForm(); | |
} else { | |
self._options.onPick(); | |
self.getBoredInstance(); | |
} | |
return false; | |
}); | |
this.includeCss(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment