瀏覽代碼

Updates for release v4.1.5

Kartik Visweswaran 10 年之前
父節點
當前提交
3c2994a058
共有 8 個文件被更改,包括 47 次插入47 次删除
  1. 4 1
      CHANGE.md
  2. 11 12
      README.md
  3. 1 1
      bower.json
  4. 1 1
      css/fileinput.css
  5. 1 1
      css/fileinput.min.css
  6. 1 1
      examples/index.html
  7. 28 25
      js/fileinput.js
  8. 0 5
      js/fileinput.min.js

+ 4 - 1
CHANGE.md

@@ -1,8 +1,11 @@
 version 4.1.5
 =============
-**Date:** 02-Jan-2015
+**Date:** 05-Jan-2015
 
 1. (bug #100, #101): Set right params for error thrown during reading of files.
+2. (bug #104): Fix formdata not defined.
+3. (enh #105): Expose current jqXHR object on ajax events.
+4. (enh #106): Enhance events for ajax requests and enable cancelling sync uploads
 
 version 4.1.4
 =============

+ 11 - 12
README.md

@@ -961,7 +961,7 @@ $('#input-id').on('fileunlock', function(event, filestack, extraData) {
 This event is triggered before deletion of each thumbnail file in the `initialPreview` content set. Additional parameters available are: 
 
 - `key`: the key passed within `initialPreviewConfig` for the selected file for delete.
-- `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction.
+- `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 
 ```js
 $('#input-id').on('filepredelete', function(event, key, jqXHR) {
@@ -973,6 +973,7 @@ $('#input-id').on('filepredelete', function(event, key, jqXHR) {
 This event is triggered after deletion of each thumbnail file in the `initialPreview` content set. Additional parameters available are: 
 
 - `key`: the key passed within `initialPreviewConfig` for the selected file that will be passed as POST data to the `url`.
+- `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 
 ```js
 $('#input-id').on('filedelete', function(event, key) {
@@ -993,6 +994,7 @@ This event is triggered when an error is faced in deletion of each thumbnail fil
 - `data`: this is always null for `filedeleteerror`.
 - `previewId`: the identifier of the preview thumbnail container.
 - `index`: the zero-based index of the file in the preview container.
+- `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 
 ```js
 $('#input-id').on('filedeleteerror', function(event, data, preview, index) {
@@ -1009,9 +1011,9 @@ This event is triggered before upload of each thumbnail file. Additional paramet
     - `extra`: the `uploadExtraData` settings for the plugin (or empty object if not available).
     - `response`: the data sent via ajax response (or empty object if not available).
     - `reader`: the FileReader instance if available
+    - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 - `previewId`: the identifier of the preview thumbnail container.
 - `index`: the zero-based index of the file in the preview container.
-- `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction.
 
 ```js
 $('#input-id').on('filepreupload', function(event, data, previewId, index, jqXHR) {
@@ -1031,6 +1033,7 @@ asynchronous batch uploads after each file in the selection is uploaded via ajax
     - `extra`: the `uploadExtraData` settings for the plugin (or empty object if not available).
     - `response`: the data sent via ajax response (or empty object if not available).
     - `reader`: the FileReader instance if available
+    - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 - `previewId`: the identifier of each file's parent thumbnail div element in the preview window.
 - `index`: the zero-based index of the file in the file stack.
 
@@ -1051,6 +1054,7 @@ This event is triggered when an upload or file input validation error is encount
     - `extra`: the `uploadExtraData` settings for the plugin (or empty object if not available).
     - `response`: the data sent via ajax response (or empty object if not available).
     - `reader`: the FileReader instance if available
+    - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 - `previewId`: the identifier of each file's parent thumbnail div element in the preview window.
 - `index`: the zero-based index of the file in the file stack.
 
@@ -1072,7 +1076,7 @@ Additional parameters available are:
     - `extra`: the `uploadExtraData` settings for the plugin (or empty object if not available).
     - `response`: the data sent via ajax response (or empty object if not available).
     - `reader`: the FileReader instance if available
-- `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction.
+    - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 
 ```js
 $('#input-id').on('filebatchpreupload', function(event, data, jqXHR) {
@@ -1109,6 +1113,7 @@ This event is triggered when any error is faced in the synchronous batch upload
     - `extra`: the `uploadExtraData` settings for the plugin (or empty object if not available).
     - `response`: the data sent via ajax response (or empty object if not available).
     - `reader`: the FileReader instance if available
+    - `jqXHR`: the `jQuery XMLHttpRequest` object used for this transaction (if available).
 
 ```js
 $('#input-id').on('filebatchuploaderror', function(event, data) {
@@ -1121,17 +1126,11 @@ $('#input-id').on('filebatchuploaderror', function(event, data) {
 #### filebatchuploadcomplete
 This event is triggered after completion of either the synchronous OR asynchronous ajax batch upload. Additional parameters available are: 
 
-- `data`: This is a data object (associative array) that sends the following information, whose keys are:
-    - `form`: the FormData object which is passed via XHR2 (or empty object if not available).
-    - `files`: the file stack array (or empty object if not available).
-    - `extra`: the `uploadExtraData` settings for the plugin (or empty object if not available).
-    - `response`: the data sent via ajax response (or empty object if not available).
-    - `reader`: the FileReader instance if available
+- `files`: the file stack array (or empty object if not available).
+- `extra`: the `uploadExtraData` settings for the plugin (or empty object if not available).
 
 ```js
-$('#input-id').on('filebatchuploadcomplete', function(event, data) {
-    var form = data.form, files = data.files, extra = data.extra, 
-        response = data.response, reader = data.reader;
+$('#input-id').on('filebatchuploadcomplete', function(event, files, extra) {
     console.log('File batch upload complete');
 });
 ```

+ 1 - 1
bower.json

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

+ 1 - 1
css/fileinput.css

@@ -1,7 +1,7 @@
 /*!
  * @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
  * @package bootstrap-fileinput
- * @version 4.1.4
+ * @version 4.1.5
  *
  * File input styling for Bootstrap 3.0
  * Built for Yii Framework 2.0

+ 1 - 1
css/fileinput.min.css

@@ -1,7 +1,7 @@
 /*!
  * @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
  * @package bootstrap-fileinput
- * @version 4.1.4
+ * @version 4.1.5
  *
  * File input styling for Bootstrap 3.0
  * Built for Yii Framework 2.0

+ 1 - 1
examples/index.html

@@ -1,5 +1,5 @@
 <!DOCTYPE html>
-<!-- release v4.1.4, copyright 2014 Kartik Visweswaran -->
+<!-- release v4.1.5, copyright 2014 Kartik Visweswaran -->
 <html lang="en">
     <head>
         <meta charset="UTF-8"/>

+ 28 - 25
js/fileinput.js

@@ -1,6 +1,6 @@
 /*!
  * @copyright Copyright &copy; Kartik Visweswaran, Krajee.com, 2014
- * @version 4.1.4
+ * @version 4.1.5
  *
  * File input styled for Bootstrap 3.0 that utilizes HTML5 File Input's advanced 
  * features including the FileReader API. 
@@ -332,14 +332,16 @@
             return isSet(t, self.previewTemplates) ? self.previewTemplates[t] : defaultPreviewTemplates[t];
         },
         getOutData: function () {
-            var self = this, responsedata = arguments.length > 0 ? arguments[0] : {},
-                filesdata = arguments.length > 1 ? arguments[1] : self.filestack;
+            var self = this, jqXHR = arguments.length > 0 ? arguments[0] : {},
+                responsedata = arguments.length > 1 ? arguments[1] : {},
+                filesdata = arguments.length > 2 ? arguments[2] : self.filestack;
             return {
                 form: self.formdata,
                 files: filesdata,
                 extra: self.getExtraData(),
                 response: responsedata,
-                reader: self.reader
+                reader: self.reader,
+                jqXHR: jqXHR
             };
         },
         listen: function () {
@@ -653,9 +655,9 @@
                         },
                         success: function(data, textStatus, jqXHR) {
                             if(typeof data.error === 'undefined') {
-                                self.raise('filedeleted', [vKey]);
+                                self.raise('filedeleted', [vKey, jqXHR]);
                             } else {
-                                self.showError(data.error, null, $el.attr('id'), key, 'filedeleteerror');
+                                self.showError(data.error, null, $el.attr('id'), key, 'filedeleteerror', jqXHR);
                                 resetProgress();
                             }
                             $frame.removeClass('file-uploading').addClass('file-deleted');
@@ -684,7 +686,7 @@
                             });
                         },
                         error: function(jqXHR, textStatus, errorThrown) {
-                            self.showError(errorThrown, null, $el.attr('id'), key, 'filedeleteerror');
+                            self.showError(errorThrown, null, $el.attr('id'), key, 'filedeleteerror', jqXHR);
                             $frame.removeClass('file-uploading');
                             resetProgress();
                         }
@@ -917,7 +919,7 @@
                 processData: false,
                 contentType: false,
                 beforeSend: function(jqXHR) {
-                    var outData = self.getOutData();
+                    var outData = self.getOutData(jqXHR);
                     setIndicator('indicatorLoading', 'indicatorLoadingTitle');
                     addCss($thumb, 'file-uploading');
                     $btnUpload.attr('disabled', true);
@@ -925,10 +927,10 @@
                     if (!allFiles) {
                         self.lock();
                     }
-                    self.raise('filepreupload', [outData, previewId, i, jqXHR])
+                    self.raise('filepreupload', [outData, previewId, i])
                 },
                 success: function(data, textStatus, jqXHR) {
-                    var outData = self.getOutData(data);
+                    var outData = self.getOutData(jqXHR, data);
                     setTimeout(function() {
                         if(typeof data.error === 'undefined') {
                             setIndicator('indicatorSuccess', 'indicatorSuccessTitle');
@@ -950,7 +952,7 @@
                 },
                 error: function(jqXHR, textStatus, errorThrown) {
                     setIndicator('indicatorError', 'indicatorErrorTitle');
-                    var outData = self.getOutData();
+                    var outData = self.getOutData(jqXHR);
                     if (allFiles) {
                         var cap = files[i].name;
                         self.showUploadError('<b>' + cap + '</b>: ' + errorThrown, outData, previewId, i);
@@ -961,12 +963,12 @@
             }));
         },
         uploadBatch: function() {
-            var self = this, files = self.filestack, total = files.length;
-            self.formdata = new FormData();
+            var self = this, files = self.filestack, total = files.length, formdata = new FormData();
+            self.formdata = formdata;
             if (total == 0) {
                 return;
             }
-            var config = self.fileActionSettings, formdata = self.formdata,
+            var config = self.fileActionSettings,
                 setIndicator = function (i, icon, msg) {
                     var $indicator = $('#' + self.previewInitId + "-" + i).find('.file-upload-indicator');
                     $indicator.html(config[icon]);
@@ -992,7 +994,7 @@
                 }
             });
             self.uploadExtra(formdata);
-            $.ajax({
+            self.ajaxRequests.push($.ajax({
                 xhr: function() {
                     var xhrobj = $.ajaxSettings.xhr();
                     return self.initXhr(xhrobj, 98);
@@ -1006,7 +1008,7 @@
                 contentType: false,
                 beforeSend: function(jqXHR) {
                     self.lock();
-                    var outData = self.getOutData();
+                    var outData = self.getOutData(jqXHR);
                     if (!self.showPreview) {
                         return;
                     }
@@ -1016,10 +1018,10 @@
                         $btnUpload.attr('disabled', true);
                         $btnDelete.attr('disabled', true);
                     });
-                    self.raise('filebatchpreupload', [outData, jqXHR]);
+                    self.raise('filebatchpreupload', [outData]);
                 },
                 success: function(data, textStatus, jqXHR) {
-                    var outData = self.getOutData(data);
+                    var outData = self.getOutData(jqXHR, data);
                     var keys = isEmpty(data.errorkeys) ? [] : data.errorkeys;
                     if(typeof data.error === 'undefined' || isEmpty(data.error)) {
                         self.raise('filebatchuploadsuccess', [outData]);
@@ -1062,14 +1064,14 @@
                     self.clearFileInput();
                 },
                 error: function(jqXHR, textStatus, errorThrown) {
-                    var outData = self.getOutData();
+                    var outData = self.getOutData(jqXHR);
                     self.showUploadError(errorThrown, outData, null, null, 'filebatchuploaderror');
                     self.uploadFileCount = total - 1;
                     self.$preview.find('.file-preview-frame').removeClass('file-uploading');
                     self.$preview.find('.file-preview-frame kv-file-upload').removeAttr('disabled');
                     self.$preview.find('.file-preview-frame kv-file-delete').removeAttr('disabled');
                 }
-            });
+            }));
         },
         hideFileIcon: function () {
             if (this.overwriteInitial) {
@@ -1091,7 +1093,7 @@
             }
         },
         showUploadError: function (msg, data, previewId, index) {
-            var self = this, $error = self.$errorContainer, 
+            var self = this, $error = self.$errorContainer,
                 ev = arguments.length > 4 ? arguments[4] : 'fileuploaderror';
             if ($error.find('ul').length == 0) {
                 $error.html('<ul class="text-left"><li>' + msg + '</li></ul>');
@@ -1105,10 +1107,11 @@
         },
         showError: function (msg, file, previewId, index) {
             var self = this, $error = self.$errorContainer,
-                ev = arguments.length > 4 ? arguments[4] : 'fileerror';
+                ev = arguments.length > 4 ? arguments[4] : 'fileerror',
+                jqXHR = arguments.length > 5 ? arguments[5] : {};
             $error.html(msg);
             $error.fadeIn(800);
-            self.raise(ev, [file, previewId, index, self.reader]);
+            self.raise(ev, [file, previewId, index, self.reader, jqXHR]);
             if (!self.isUploadable) {
                 self.clearFileInput();
             }
@@ -1243,7 +1246,7 @@
                 ctr = self.filestack.length, 
                 throwError = function(msg, file, previewId, index) {
                     self.previewDefault(file, previewId, true);
-                    var outData = self.getOutData({}, files);
+                    var outData = self.getOutData({}, {}, files);
                     return self.isUploadable ? self.showUploadError(msg, outData, previewId, index) : self.showError(msg, file, previewId, index);
                 };
             function readFile(i) {
@@ -1377,7 +1380,7 @@
                 numFiles = !isEmpty(files) ? (files.length + self.initialPreviewCount) : 1, tfiles,
                 ctr = self.filestack.length, isAjaxUpload = (self.isUploadable && ctr != 0),
                 throwError = function(msg, file, previewId, index) {
-                    var outData = self.getOutData({}, files);
+                    var outData = self.getOutData({}, {}, files);
                     return self.isUploadable ? self.showUploadError(msg, outData, previewId, index) : self.showError(msg, file, previewId, index);
                 };
             self.resetUpload();

文件差異過大導致無法顯示
+ 0 - 5
js/fileinput.min.js


部分文件因文件數量過多而無法顯示