Browse Source

Upgraded to release v1.7.0

Kartik Visweswaran 11 năm trước cách đây
mục cha
commit
652a630e4e
5 tập tin đã thay đổi với 44 bổ sung20 xóa
  1. 10 0
      CHANGE.md
  2. 1 1
      README.md
  3. 1 1
      bower.json
  4. 32 18
      js/fileinput.js
  5. 0 0
      js/fileinput.min.js

+ 10 - 0
CHANGE.md

@@ -1,3 +1,13 @@
+version 1.7.0
+=============
+Date: 02-Jul-2014
+
+### Additions
+1. The plugin now offers an additional `overwriteInitial` option. This is by default set to `false`. When set to `false`, this will always show the 
+  `initialPreview` content at the beginning (when uploading or during clear). If set to `true` any `initialPreview` content set will be overwritten, 
+   when new file is uploaded or when files are cleared. Setting it to `false` will help displaying a saved image or file from database always - 
+   especially when using the `multiple` file upload feature.
+
 version 1.6.0
 =============
 Date: 03-Jun-2014

+ 1 - 1
README.md

@@ -5,7 +5,7 @@ An enhanced HTML 5 file input for Bootstrap 3.x with file preview for images and
 
 ![File Input Screenshot](https://lh6.googleusercontent.com/-2niyujIaat0/UyqzA_78OQI/AAAAAAAAADE/f6IJkr11uA8/w666-h418-no/fileinput-screenshot.jpg)
 
-> NOTE: The latest version of the plugin v1.6.0 has been released. Refer the [CHANGE LOG](https://github.com/kartik-v/bootstrap-fileinput/blob/master/CHANGE.md) for details.
+> NOTE: The latest version of the plugin v1.7.0 has been released. Refer the [CHANGE LOG](https://github.com/kartik-v/bootstrap-fileinput/blob/master/CHANGE.md) for details.
 
 ## Features  
 

+ 1 - 1
bower.json

@@ -1,6 +1,6 @@
 {
     "name": "bootstrap-fileinput",
-    "version": "1.6.0",
+    "version": "1.7.0",
     "homepage": "https://github.com/kartik-v/bootstrap-fileinput",
     "authors": [
         "Kartik Visweswaran <[email protected]>"

+ 32 - 18
js/fileinput.js

@@ -1,6 +1,6 @@
 /*!
  * @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2013
- * @version 1.6.0
+ * @version 1.7.0
  *
  * File input styled for Bootstrap 3.0 that utilizes HTML5 File Input's advanced 
  * features including the FileReader API. This plugin is inspired by the blog article at
@@ -89,6 +89,7 @@
             self.showPreview = options.showPreview;
             self.initialPreview = options.initialPreview;
             self.initialCaption = options.initialCaption;
+            self.overwriteInitial = options.overwriteInitial;
             self.showRemove = options.showRemove;
             self.showUpload = options.showUpload;
             self.captionClass = options.captionClass;
@@ -162,7 +163,6 @@
                 for (var i = 0; i < len; i++) {
                     html += '<div class="file-preview-frame">' + content[i] + "</div>\n";
                 }
-                self.$preview.html(html);
                 if (len > 1 && cap == 0) {
                     caption = len + ' files selected';
                 }
@@ -173,6 +173,7 @@
             else {
                 return;
             }
+            self.initialPreviewContent = html;
             self.$preview.html(html);
             self.$caption.html(caption);
             self.$container.removeClass('file-input-new');
@@ -187,9 +188,16 @@
                 self.$element.trigger('change');
                 self.$element.trigger('fileclear');
             }
-            self.$preview.html('');
-            self.$caption.html('');
-            self.$container.removeClass('file-input-new').addClass('file-input-new');
+            if (self.overwriteInitial) {
+                self.$preview.html('');
+                self.$caption.html('');
+                self.$container.removeClass('file-input-new').addClass('file-input-new');
+            }
+            else {
+                self.$preview.html(self.original.preview);
+                self.$caption.html(self.original.caption);
+                self.$container.removeClass('file-input-new');
+            }
         },
         reset: function (e) {
             var self = this;
@@ -205,8 +213,8 @@
         change: function (e) {
             var self = this;
             var elem = self.$element, files = elem.get(0).files, numFiles = files ? files.length : 1,
-                label = elem.val().replace(/\\/g, '/').replace(/.*\//, ''), preview = self.$preview,
-                container = self.$previewContainer, status = self.$previewStatus, msgLoading = self.msgLoading,
+                label = elem.val().replace(/\\/g, '/').replace(/.*\//, ''), $preview = self.$preview,
+                $container = self.$previewContainer, $status = self.$previewStatus, msgLoading = self.msgLoading,
                 msgProgress = self.msgProgress, msgSelected = self.msgSelected, tfiles,
                 fileType = self.previewFileType, wrapLen = parseInt(self.wrapTextLength),
                 wrapInd = self.wrapIndicator;
@@ -222,19 +230,22 @@
             if (tfiles.length === 0) {
                 return;
             }
-            preview.html('');
-            var total = tfiles.length, self = self;
+            $preview.html('');
+            if (!self.overwriteInitial) {
+                $preview.html(self.initialPreviewContent);
+            }
+            var total = tfiles.length;
             for (var i = 0; i < total; i++) {
                 (function (file) {
                     var caption = file.name;
                     var isImg = isImageFile(file.type, file.name);
                     var isTxt = isTextFile(file.type, file.name);
-                    if (preview.length > 0 && (fileType == "any" ? (isImg || isTxt) : (fileType == "text" ? isTxt : isImg)) && typeof FileReader !== "undefined") {
+                    if ($preview.length > 0 && (fileType == "any" ? (isImg || isTxt) : (fileType == "text" ? isTxt : isImg)) && typeof FileReader !== "undefined") {
                         var reader = new FileReader();
-                        status.html(msgLoading);
-                        container.addClass('loading');
+                        $status.html(msgLoading);
+                        $container.addClass('loading');
                         reader.onload = function (theFile) {
-                            var content = '', modal = "";
+                            var content = '', modal = '';
                             if (isTxt) {
                                 var strText = theFile.target.result;
                                 if (strText.length > wrapLen) {
@@ -248,17 +259,17 @@
                             else {
                                 content = '<div class="file-preview-frame"><img src="' + theFile.target.result + '" class="file-preview-image" title="' + caption + '" alt="' + caption + '"></div>';
                             }
-                            preview.append("\n" + content);
+                            $preview.append("\n" + content);
                             if (i >= total - 1) {
-                                container.removeClass('loading');
-                                status.html('');
+                                $container.removeClass('loading');
+                                $status.html('');
                             }
                         };
                         reader.onprogress = function (data) {
                             if (data.lengthComputable) {
                                 var progress = parseInt(((data.loaded / data.total) * 100), 10);
                                 var msg = msgProgress.replace('{percent}', progress).replace('{file}', file.name);
-                                status.html(msg);
+                                $status.html(msg);
                             }
                         };
                         if (isTxt) {
@@ -269,10 +280,11 @@
                         }
                     }
                     else {
-                        preview.append("\n" + '<div class="file-preview-frame"><div class="file-preview-other"><h2><i class="glyphicon glyphicon-file"></i></h2>' + caption + '</div></div>');
+                        $preview.append("\n" + '<div class="file-preview-frame"><div class="file-preview-other"><h2><i class="glyphicon glyphicon-file"></i></h2>' + caption + '</div></div>');
                     }
                 })(tfiles[i]);
             }
+
             var log = numFiles > 1 ? msgSelected.replace('{n}', numFiles) : label;
             self.$caption.html(log);
             self.$container.removeClass('file-input-new');
@@ -380,6 +392,8 @@
         mainTemplate: null,
         initialPreview: '',
         initialCaption: '',
+        initialPreviewContent: '',
+        overwriteInitial: false,
         previewTemplate: PREVIEW_TEMPLATE,
         captionTemplate: CAPTION_TEMPLATE,
         browseLabel: 'Browse &hellip;',

Những thai đổi đã bị hủy bỏ vì nó quá lớn
+ 0 - 0
js/fileinput.min.js


Một số tệp đã không được hiển thị bởi vì quá nhiều tập tin thay đổi trong này khác