Skip to content

Commit c968750

Browse files
committed
Merge pull request JeremyFagis#24 from oforia/master
Added new options
2 parents 80afd6e + 4def577 commit c968750

File tree

3 files changed

+56
-8
lines changed

3 files changed

+56
-8
lines changed

dist/js/dropify.js

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,10 @@ function Dropify(element, options) {
3939
showRemove: true,
4040
showLoader: true,
4141
showErrors: true,
42+
errorTimeout: 3000,
4243
errorsPosition: 'overlay',
4344
allowedFormats: ['portrait', 'square', 'landscape'],
45+
allowedFileExtensions: ['*'],
4446
messages: {
4547
'default': 'Drag and drop a file here or click',
4648
'replace': 'Drag and drop or click to replace',
@@ -53,7 +55,8 @@ function Dropify(element, options) {
5355
'maxWidth': 'The image width is too big ({{ value }}}px max).',
5456
'minHeight': 'The image height is too small ({{ value }}}px min).',
5557
'maxHeight': 'The image height is too big ({{ value }}px max).',
56-
'imageFormat': 'The image format is not allowed ({{ value }} only).'
58+
'imageFormat': 'The image format is not allowed ({{ value }} only).',
59+
'fileExtension': 'The file is not allowed ({{ value }} only).'
5760
},
5861
tpl: {
5962
wrap: '<div class="dropify-wrapper"></div>',
@@ -192,6 +195,8 @@ Dropify.prototype.readFile = function(input)
192195
this.errorsEvent.errors = [];
193196

194197
this.checkFileSize();
198+
199+
this.isFileExtensionAllowed();
195200

196201
reader.onload = function(_file) {
197202
srcBase64 = _file.target.result;
@@ -235,7 +240,7 @@ Dropify.prototype.onFileReady = function(event, src)
235240
this.errorsContainer.addClass('visible');
236241

237242
var errorsContainer = this.errorsContainer;
238-
setTimeout(function(){ errorsContainer.removeClass('visible'); }, 1000);
243+
setTimeout(function(){ errorsContainer.removeClass('visible'); }, this.settings.errorTimeout);
239244
}
240245

241246
this.wrapper.addClass('has-error');
@@ -412,6 +417,23 @@ Dropify.prototype.isImage = function()
412417
return false;
413418
};
414419

420+
/**
421+
* Test if the file extension is allowed
422+
*
423+
* @return {Boolean}
424+
*/
425+
Dropify.prototype.isFileExtensionAllowed = function () {
426+
427+
if (this.settings.allowedFileExtensions.indexOf('*') != "-1") {
428+
return true;
429+
} else if (this.settings.allowedFileExtensions.indexOf(this.getFileType()) != "-1") {
430+
return true;
431+
}
432+
this.pushError("fileExtension");
433+
434+
return false;
435+
}
436+
415437
/**
416438
* Translate messages if needed.
417439
*/
@@ -562,7 +584,9 @@ Dropify.prototype.getError = function(errorKey)
562584
value = this.settings.maxHeight;
563585
} else if (errorKey === 'imageFormat') {
564586
value = this.settings.allowedFormats.join(' ');
565-
}
587+
} else if (errorKey === 'fileExtension') {
588+
value = this.settings.allowedFileExtensions.join(', ');
589+
}
566590

567591
if (value !== '') {
568592
return error.replace('{{ value }}', value);

0 commit comments

Comments
 (0)