Add progress and upload progress callbacks for AjaxRequest
authorMatthias Schmidt <gravatronics@live.com>
Wed, 23 Sep 2015 16:09:47 +0000 (18:09 +0200)
committerMatthias Schmidt <gravatronics@live.com>
Wed, 23 Sep 2015 16:09:47 +0000 (18:09 +0200)
wcfsetup/install/files/js/WoltLab/WCF/Ajax/Request.js

index f329ac1db2dd35adfce9f55003edb40ea909b6f8..917c5d6986f163379238cefd774193ae697bb21b 100644 (file)
@@ -50,6 +50,8 @@ define(['Core', 'Language', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Dialog', 'Wolt
                                failure: null,
                                finalize: null,
                                success: null,
+                               progress: null,
+                               uploadProgress: null,
                                
                                callbackObject: null
                        }, options);
@@ -68,6 +70,8 @@ define(['Core', 'Language', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Dialog', 'Wolt
                                if (typeof this._options.callbackObject._ajaxFailure === 'function') this._options.failure = this._options.callbackObject._ajaxFailure.bind(this._options.callbackObject);
                                if (typeof this._options.callbackObject._ajaxFinalize === 'function') this._options.finalize = this._options.callbackObject._ajaxFinalize.bind(this._options.callbackObject);
                                if (typeof this._options.callbackObject._ajaxSuccess === 'function') this._options.success = this._options.callbackObject._ajaxSuccess.bind(this._options.callbackObject);
+                               if (typeof this._options.callbackObject._ajaxProgress === 'function') this._options.progress = this._options.callbackObject._ajaxProgress.bind(this._options.callbackObject);
+                               if (typeof this._options.callbackObject._ajaxUploadProgress === 'function') this._options.uploadProgress = this._options.callbackObject._ajaxUploadProgress.bind(this._options.callbackObject);
                        }
                        
                        if (_didInit === false) {
@@ -124,6 +128,13 @@ define(['Core', 'Language', 'Dom/ChangeListener', 'Dom/Util', 'Ui/Dialog', 'Wolt
                                self._failure(this, options);
                        };
                        
+                       if (this._options.progress) {
+                               this._xhr.onprogress = this._options.progress;
+                       }
+                       if (this._options.uploadProgress) {
+                               this._xhr.upload.onprogress = this._options.uploadProgress;
+                       }
+                       
                        if (this._options.type === 'POST') {
                                var data = this._options.data;
                                if (typeof data === 'object') {