Skip to content

Commit 6ca9f20

Browse files
committed
Fix #330: Minor enhancements in validating preview and progress bar display
1 parent d9ce248 commit 6ca9f20

File tree

3 files changed

+35
-32
lines changed

3 files changed

+35
-32
lines changed

CHANGE.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
version 4.2.1
22
=============
3-
**Date**: 14-Jun-2015
3+
**Date**: 15-Jun-2015
44

55
1. (enh #279, #280): Fixed error for failed response types.
66
2. (enh #287): Add Brazilian Portugese (pt-BR) translations.
@@ -32,6 +32,7 @@ version 4.2.1
3232
- `msgImageWidthLarge`
3333
- `msgImageHeightLarge`
3434
17. (enh #329): Message translation updates.
35+
18. (enh #330): Minor enhancements in validating preview and progress bar display.
3536

3637
version 4.2.0
3738
=============

js/fileinput.js

+31-29
Original file line numberDiff line numberDiff line change
@@ -686,7 +686,7 @@
686686
},
687687
noFilesError: function (params) {
688688
var self = this, label = self.minFileCount > 1 ? self.filePlural : self.fileSingle,
689-
msg = self.msgFilesTooLess.repl('{n}', self.minFileCount).repl('{files}', label),
689+
msg = self.msgFilesTooLess.replace('{n}', self.minFileCount).replace('{files}', label),
690690
$error = self.$errorContainer;
691691
$error.html(msg);
692692
self.isError = true;
@@ -699,7 +699,9 @@
699699
setProgress: function (p) {
700700
var self = this, pct = Math.min(p, 100),
701701
template = pct < 100 ? self.progressTemplate : self.progressCompleteTemplate;
702-
self.$progress.html(template.repl('{percent}', pct));
702+
if (!isEmpty(template)) {
703+
self.$progress.html(template.repl('{percent}', pct));
704+
}
703705
},
704706
upload: function () {
705707
var self = this, totLen = self.getFileStack().length, params = {},
@@ -867,7 +869,7 @@
867869
self.reset();
868870
} else {
869871
n = chk + len;
870-
cap = n > 1 ? self.getMsgSelected(n) : filestack[0].name;
872+
cap = n > 1 ? self.getMsgSelected(n) : (filestack[0] ? filestack[0].name : '');
871873
self.setCaption(cap);
872874
}
873875
});
@@ -884,7 +886,7 @@
884886
},
885887
getMsgSelected: function (n) {
886888
var self = this, strFiles = n === 1 ? self.fileSingle : self.filePlural;
887-
return self.msgSelected.repl('{n}', n).repl('{files}', strFiles);
889+
return self.msgSelected.replace('{n}', n).replace('{files}', strFiles);
888890
},
889891
renderFileFooter: function (caption, width) {
890892
var self = this, config = self.fileActionSettings, footer, out,
@@ -949,8 +951,8 @@
949951
var self = this, $thumbs = !self.showUploadedThumbs ? self.$preview.find('.file-preview-frame') :
950952
self.$preview.find('.file-preview-frame:not(.file-preview-success)');
951953
$thumbs.remove();
952-
if (!self.$preview.find('.file-preview-frame').length) {
953-
self.resetErrors();
954+
if (!self.$preview.find('.file-preview-frame').length || !self.showPreview) {
955+
self.resetUpload();
954956
}
955957
},
956958
initPreview: function (isInit) {
@@ -1628,19 +1630,19 @@
16281630
var self = this, err = evt.target.error;
16291631
switch (err.code) {
16301632
case err.NOT_FOUND_ERR:
1631-
self.showError(self.msgFileNotFound.repl('{name}', caption));
1633+
self.showError(self.msgFileNotFound.replace('{name}', caption));
16321634
break;
16331635
case err.SECURITY_ERR:
1634-
self.showError(self.msgFileSecured.repl('{name}', caption));
1636+
self.showError(self.msgFileSecured.replace('{name}', caption));
16351637
break;
16361638
case err.NOT_READABLE_ERR:
1637-
self.showError(self.msgFileNotReadable.repl('{name}', caption));
1639+
self.showError(self.msgFileNotReadable.replace('{name}', caption));
16381640
break;
16391641
case err.ABORT_ERR:
1640-
self.showError(self.msgFilePreviewAborted.repl('{name}', caption));
1642+
self.showError(self.msgFilePreviewAborted.replace('{name}', caption));
16411643
break;
16421644
default:
1643-
self.showError(self.msgFilePreviewError.repl('{name}', caption));
1645+
self.showError(self.msgFilePreviewError.replace('{name}', caption));
16441646
}
16451647
},
16461648
parseFileType: function (file) {
@@ -1772,9 +1774,9 @@
17721774
}
17731775
fileSize = fileSize.toFixed(2);
17741776
if (self.maxFileSize > 0 && fileSize > self.maxFileSize) {
1775-
msg = self.msgSizeTooLarge.repl('{name}', caption)
1776-
.repl('{size}', fileSize)
1777-
.repl('{maxSize}', self.maxFileSize);
1777+
msg = self.msgSizeTooLarge.replace('{name}', caption)
1778+
.replace('{size}', fileSize)
1779+
.replace('{maxSize}', self.maxFileSize);
17781780
self.isError = throwError(msg, file, previewId, i);
17791781
return;
17801782
}
@@ -1786,7 +1788,7 @@
17861788
fileCount += isEmpty(chk) ? 0 : chk.length;
17871789
}
17881790
if (fileCount === 0) {
1789-
msg = self.msgInvalidFileType.repl('{name}', caption).repl('{types}', strTypes);
1791+
msg = self.msgInvalidFileType.replace('{name}', caption).replace('{types}', strTypes);
17901792
self.isError = throwError(msg, file, previewId, i);
17911793
return;
17921794
}
@@ -1795,7 +1797,7 @@
17951797
chk = caption.match(fileExtExpr);
17961798
fileCount += isEmpty(chk) ? 0 : chk.length;
17971799
if (fileCount === 0) {
1798-
msg = self.msgInvalidFileExtension.repl('{name}', caption).repl('{extensions}',
1800+
msg = self.msgInvalidFileExtension.replace('{name}', caption).replace('{extensions}',
17991801
strExt);
18001802
self.isError = throwError(msg, file, previewId, i);
18011803
return;
@@ -1808,7 +1810,7 @@
18081810
return;
18091811
}
18101812
if ($preview.length > 0 && FileReader !== undefined) {
1811-
$status.html(msgLoading.repl('{index}', i + 1).repl('{files}', numFiles));
1813+
$status.html(msgLoading.replace('{index}', i + 1).replace('{files}', numFiles));
18121814
$container.addClass('loading');
18131815
reader.onerror = function (evt) {
18141816
self.errorHandler(evt, caption);
@@ -1819,8 +1821,8 @@
18191821
};
18201822
reader.onloadend = function () {
18211823
msg = msgProgress
1822-
.repl('{index}', i + 1).repl('{files}', numFiles)
1823-
.repl('{percent}', 50).repl('{name}', caption);
1824+
.replace('{index}', i + 1).replace('{files}', numFiles)
1825+
.replace('{percent}', 50).replace('{name}', caption);
18241826
setTimeout(function () {
18251827
$status.html(msg);
18261828
readFile(i + 1);
@@ -1831,8 +1833,8 @@
18311833
reader.onprogress = function (data) {
18321834
if (data.lengthComputable) {
18331835
var fact = (data.loaded / data.total) * 100, progress = Math.ceil(fact);
1834-
msg = msgProgress.repl('{index}', i + 1).repl('{files}', numFiles)
1835-
.repl('{percent}', progress).repl('{name}', caption);
1836+
msg = msgProgress.replace('{index}', i + 1).replace('{files}', numFiles)
1837+
.replace('{percent}', progress).replace('{name}', caption);
18361838
setTimeout(function () {
18371839
$status.html(msg);
18381840
}, 100);
@@ -1933,7 +1935,7 @@
19331935
self.resetErrors();
19341936
total = self.isUploadable ? self.getFileStack().length + tfiles.length : tfiles.length;
19351937
if (self.maxFileCount > 0 && total > self.maxFileCount) {
1936-
msg = self.msgFilesTooMany.repl('{m}', self.maxFileCount).repl('{n}', total);
1938+
msg = self.msgFilesTooMany.replace('{m}', self.maxFileCount).replace('{n}', total);
19371939
self.isError = throwError(msg, null, null, null);
19381940
self.$captionContainer.find('.kv-caption-icon').hide();
19391941
self.setCaption('', true);
@@ -1996,18 +1998,18 @@
19961998
});
19971999
},
19982000
checkDimensions: function (i, chk, $img, $thumb, fname, type, params) {
1999-
var self = this, dim, msg, tag = chk === 'Small' ? 'min' : 'max',
2000-
limit = self[tag + 'Image' + type], test, $imgEl = $img[0];
2001-
if (isEmpty(limit)) {
2001+
var self = this, msg, dim, tag = chk === 'Small' ? 'min' : 'max',
2002+
limit = self[tag + 'Image' + type], $imgEl, isValid;
2003+
if (isEmpty(limit) || !$img.length ) {
20022004
return;
20032005
}
2004-
msg = self['msgImage' + type + chk];
2006+
$imgEl = $img[0];
20052007
dim = (type === 'Width') ? $imgEl.naturalWidth || $imgEl.width : $imgEl.naturalHeight || $imgEl.height;
2006-
test = chk === 'Small' ? dim >= limit : dim <= limit;
2007-
if (!$img.length || test) {
2008+
isValid = chk === 'Small' ? dim >= limit : dim <= limit;
2009+
if (isValid) {
20082010
return;
20092011
}
2010-
msg = msg.replace('{name}', fname).replace('{size}', limit);
2012+
msg = self['msgImage' + type + chk].replace('{name}', fname).replace('{size}', limit);
20112013
self.showUploadError(msg, params);
20122014
self.setThumbStatus($thumb, 'Error');
20132015
self.filestack[i] = null;

0 commit comments

Comments
 (0)