Kaynağa Gözat

Fix #22: File caption message enhancements

Kartik Visweswaran 11 yıl önce
ebeveyn
işleme
78a3e3348c
3 değiştirilmiş dosya ile 18 ekleme ve 8 silme
  1. 9 1
      README.md
  2. 9 5
      js/fileinput.js
  3. 0 2
      js/fileinput.min.js

+ 9 - 1
README.md

@@ -32,7 +32,7 @@ An enhanced HTML 5 file input for Bootstrap 3.x with file preview for images and
 11. Upload action defaults to form submit. Supports an upload route/server action parameter for custom ajax based upload.
 12. Triggers JQuery events for advanced development. Events currently available are `filereset`, `fileclear`, `filecleared`, `fileloaded`, and `fileerror`.
 13. Disabled and readonly file input support.
-14. Size of the entire plugin is less than 6KB if gzipped. The minified assets are less than 19KB (about 16KB for the minified JS and 3KB for the minified CSS).
+14. Size of the entire plugin is less than 6KB if gzipped. The minified assets are less than 20KB (about 17KB for the minified JS and 3KB for the minified CSS).
 
 ## Demo
 
@@ -393,6 +393,14 @@ where:
 
 - `{name}`: will be replaced by the file name being uploaded
 
+#### msgValidationError
+_string_ the exception message to be displayed within the caption container (instead of `msgFilesSelected`), 
+when a validation error is encountered. Defaults to:
+
+```
+File Upload Error
+```
+
 #### msgErrorClass
 _string_ the css class for the error message to be displayed in the preview window when the file size exceeds `maxSize`. Defaults to `file-error-message`.
 

+ 9 - 5
js/fileinput.js

@@ -122,6 +122,7 @@
             self.msgFileNotReadable = options.msgFileNotReadable;
             self.msgFilePreviewAborted = options.msgFilePreviewAborted;
             self.msgFilePreviewError = options.msgFilePreviewError;
+            self.msgValidationError = options.msgValidationError;
             self.msgErrorClass = options.msgErrorClass;
             self.initialDelimiter = options.initialDelimiter;
             self.initialPreview = options.initialPreview;
@@ -176,6 +177,8 @@
             self.$previewContainer = getElement(options, 'elPreviewContainer', self.$container.find('.file-preview'));
             self.$preview = getElement(options, 'elPreviewImage', self.$container.find('.file-preview-thumbnails'));
             self.$previewStatus = getElement(options, 'elPreviewStatus', self.$container.find('.file-preview-status'));
+            var content = self.initialPreview;
+            self.initialPreviewCount = isArray(content) ? content.length : (content.length > 0 ? content.split(self.initialDelimiter).length : 0)
             self.initPreview();
             self.original = {
                 preview: self.$preview.html(),
@@ -199,9 +202,7 @@
             self.init(params);
         },
         initPreview: function () {
-            var self = this, html = '',
-                content = self.initialPreview,
-                len = isArray(content) ? content.length : (content.length > 0 ? content.split(self.initialDelimiter).length : 0),
+            var self = this, html = '', content = self.initialPreview, len = self.initialPreviewCount,
                 cap = self.initialCaption.length, previewId = "preview-" + uniqId(),
                 caption = (cap > 0) ? self.initialCaption : self.msgSelected.replace("{n}", len);
             if (isArray(content) && len > 0) {
@@ -228,7 +229,6 @@
             } else {
                 return;
             }
-            self.initialPreviewCount = len;
             self.initialPreviewContent = html;
             self.$preview.html(html);
             self.$caption.html(caption);
@@ -249,6 +249,9 @@
                 self.$element.trigger('change');
                 self.$element.trigger('fileclear');
             }
+            if (self.overwriteInitial) {
+                self.initialPreviewCount = 0;
+            }
             if (!self.overwriteInitial && !isEmpty(self.initialPreviewContent)) {
                 self.$preview.html(self.original.preview);
                 self.$caption.html(self.original.caption);
@@ -465,7 +468,7 @@
             self.reader = null;
             var log = numFiles > 1 ? msgSelected.replace('{n}', numFiles) : label;
             if (self.isError) {
-                log = numFiles > 1 ? msgSelected.replace('{n}', numFiles - 1) : ' ';
+                log = self.msgValidationError;
             }
             self.$caption.html(log);
             self.$captionContainer.attr('title', log);
@@ -606,6 +609,7 @@
         msgFileNotReadable: 'File "{name}" is not readable.',
         msgFilePreviewAborted: 'File preview aborted for "{name}".',
         msgFilePreviewError: 'An error occurred while reading the file "{name}".',
+        msgValidationError: 'File Upload Error',
         msgErrorClass: 'file-error-message',
         msgLoading: 'Loading  file {index} of {files} …',
         msgProgress: 'Loading file {index} of {files} - {name} - {percent}% completed.',

Dosya farkı çok büyük olduğundan ihmal edildi
+ 0 - 2
js/fileinput.min.js


Bu fark içinde çok fazla dosya değişikliği olduğu için bazı dosyalar gösterilmiyor