|
686 | 686 | },
|
687 | 687 | noFilesError: function (params) {
|
688 | 688 | 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), |
690 | 690 | $error = self.$errorContainer;
|
691 | 691 | $error.html(msg);
|
692 | 692 | self.isError = true;
|
|
699 | 699 | setProgress: function (p) {
|
700 | 700 | var self = this, pct = Math.min(p, 100),
|
701 | 701 | 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 | + } |
703 | 705 | },
|
704 | 706 | upload: function () {
|
705 | 707 | var self = this, totLen = self.getFileStack().length, params = {},
|
|
867 | 869 | self.reset();
|
868 | 870 | } else {
|
869 | 871 | 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 : ''); |
871 | 873 | self.setCaption(cap);
|
872 | 874 | }
|
873 | 875 | });
|
|
884 | 886 | },
|
885 | 887 | getMsgSelected: function (n) {
|
886 | 888 | 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); |
888 | 890 | },
|
889 | 891 | renderFileFooter: function (caption, width) {
|
890 | 892 | var self = this, config = self.fileActionSettings, footer, out,
|
|
949 | 951 | var self = this, $thumbs = !self.showUploadedThumbs ? self.$preview.find('.file-preview-frame') :
|
950 | 952 | self.$preview.find('.file-preview-frame:not(.file-preview-success)');
|
951 | 953 | $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(); |
954 | 956 | }
|
955 | 957 | },
|
956 | 958 | initPreview: function (isInit) {
|
|
1628 | 1630 | var self = this, err = evt.target.error;
|
1629 | 1631 | switch (err.code) {
|
1630 | 1632 | case err.NOT_FOUND_ERR:
|
1631 |
| - self.showError(self.msgFileNotFound.repl('{name}', caption)); |
| 1633 | + self.showError(self.msgFileNotFound.replace('{name}', caption)); |
1632 | 1634 | break;
|
1633 | 1635 | case err.SECURITY_ERR:
|
1634 |
| - self.showError(self.msgFileSecured.repl('{name}', caption)); |
| 1636 | + self.showError(self.msgFileSecured.replace('{name}', caption)); |
1635 | 1637 | break;
|
1636 | 1638 | case err.NOT_READABLE_ERR:
|
1637 |
| - self.showError(self.msgFileNotReadable.repl('{name}', caption)); |
| 1639 | + self.showError(self.msgFileNotReadable.replace('{name}', caption)); |
1638 | 1640 | break;
|
1639 | 1641 | case err.ABORT_ERR:
|
1640 |
| - self.showError(self.msgFilePreviewAborted.repl('{name}', caption)); |
| 1642 | + self.showError(self.msgFilePreviewAborted.replace('{name}', caption)); |
1641 | 1643 | break;
|
1642 | 1644 | default:
|
1643 |
| - self.showError(self.msgFilePreviewError.repl('{name}', caption)); |
| 1645 | + self.showError(self.msgFilePreviewError.replace('{name}', caption)); |
1644 | 1646 | }
|
1645 | 1647 | },
|
1646 | 1648 | parseFileType: function (file) {
|
|
1772 | 1774 | }
|
1773 | 1775 | fileSize = fileSize.toFixed(2);
|
1774 | 1776 | 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); |
1778 | 1780 | self.isError = throwError(msg, file, previewId, i);
|
1779 | 1781 | return;
|
1780 | 1782 | }
|
|
1786 | 1788 | fileCount += isEmpty(chk) ? 0 : chk.length;
|
1787 | 1789 | }
|
1788 | 1790 | if (fileCount === 0) {
|
1789 |
| - msg = self.msgInvalidFileType.repl('{name}', caption).repl('{types}', strTypes); |
| 1791 | + msg = self.msgInvalidFileType.replace('{name}', caption).replace('{types}', strTypes); |
1790 | 1792 | self.isError = throwError(msg, file, previewId, i);
|
1791 | 1793 | return;
|
1792 | 1794 | }
|
|
1795 | 1797 | chk = caption.match(fileExtExpr);
|
1796 | 1798 | fileCount += isEmpty(chk) ? 0 : chk.length;
|
1797 | 1799 | if (fileCount === 0) {
|
1798 |
| - msg = self.msgInvalidFileExtension.repl('{name}', caption).repl('{extensions}', |
| 1800 | + msg = self.msgInvalidFileExtension.replace('{name}', caption).replace('{extensions}', |
1799 | 1801 | strExt);
|
1800 | 1802 | self.isError = throwError(msg, file, previewId, i);
|
1801 | 1803 | return;
|
|
1808 | 1810 | return;
|
1809 | 1811 | }
|
1810 | 1812 | 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)); |
1812 | 1814 | $container.addClass('loading');
|
1813 | 1815 | reader.onerror = function (evt) {
|
1814 | 1816 | self.errorHandler(evt, caption);
|
|
1819 | 1821 | };
|
1820 | 1822 | reader.onloadend = function () {
|
1821 | 1823 | 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); |
1824 | 1826 | setTimeout(function () {
|
1825 | 1827 | $status.html(msg);
|
1826 | 1828 | readFile(i + 1);
|
|
1831 | 1833 | reader.onprogress = function (data) {
|
1832 | 1834 | if (data.lengthComputable) {
|
1833 | 1835 | 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); |
1836 | 1838 | setTimeout(function () {
|
1837 | 1839 | $status.html(msg);
|
1838 | 1840 | }, 100);
|
|
1933 | 1935 | self.resetErrors();
|
1934 | 1936 | total = self.isUploadable ? self.getFileStack().length + tfiles.length : tfiles.length;
|
1935 | 1937 | 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); |
1937 | 1939 | self.isError = throwError(msg, null, null, null);
|
1938 | 1940 | self.$captionContainer.find('.kv-caption-icon').hide();
|
1939 | 1941 | self.setCaption('', true);
|
|
1996 | 1998 | });
|
1997 | 1999 | },
|
1998 | 2000 | 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 ) { |
2002 | 2004 | return;
|
2003 | 2005 | }
|
2004 |
| - msg = self['msgImage' + type + chk]; |
| 2006 | + $imgEl = $img[0]; |
2005 | 2007 | 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) { |
2008 | 2010 | return;
|
2009 | 2011 | }
|
2010 |
| - msg = msg.replace('{name}', fname).replace('{size}', limit); |
| 2012 | + msg = self['msgImage' + type + chk].replace('{name}', fname).replace('{size}', limit); |
2011 | 2013 | self.showUploadError(msg, params);
|
2012 | 2014 | self.setThumbStatus($thumb, 'Error');
|
2013 | 2015 | self.filestack[i] = null;
|
|
0 commit comments