settings ui: Restrict file type for image file pickers.

Previously, we would allow users to pick any file, even if we didn't
support that file type.
This commit is contained in:
derAnfaenger 2017-10-27 15:42:06 +02:00 committed by Tim Abbott
parent 64025d2ce7
commit 45c21b79e1
1 changed files with 9 additions and 7 deletions

View File

@ -4,18 +4,18 @@ var upload_widget = (function () {
var default_max_file_size = 5; var default_max_file_size = 5;
function is_image_format(file) {
var type = file.type;
if (!type) {
return false;
}
var supported_types = [ var supported_types = [
'image/jpeg', 'image/jpeg',
'image/png', 'image/png',
'image/gif', 'image/gif',
'image/tiff', 'image/tiff',
]; ];
function is_image_format(file) {
var type = file.type;
if (!type) {
return false;
}
return _.indexOf(supported_types, type) >= 0; return _.indexOf(supported_types, type) >= 0;
} }
@ -60,6 +60,7 @@ var upload_widget = (function () {
return false; return false;
}); });
get_file_input().attr('accept', supported_types.toString());
get_file_input().on('change', function (e) { get_file_input().on('change', function (e) {
if (e.target.files.length === 0) { if (e.target.files.length === 0) {
input_error.hide(); input_error.hide();
@ -136,6 +137,7 @@ var upload_widget = (function () {
return false; return false;
}); });
get_file_input().attr('accept', supported_types.toString());
get_file_input().on('change', function (e) { get_file_input().on('change', function (e) {
if (e.target.files.length === 0) { if (e.target.files.length === 0) {
input_error.hide(); input_error.hide();