Closed Azq2 closed 9 years ago
http://dumpz.org/1303753/
Index: SimpleAjaxUploader.js =================================================================== --- SimpleAjaxUploader.js (revision 121436) +++ SimpleAjaxUploader.js (working copy) @@ -44,6 +44,10 @@ typeof File !== 'undefined' && typeof ( new XMLHttpRequest() ).upload !== 'undefined' ); +ss.isAjaxSupport = function () { + return XhrOk; +}; + /** * Converts object to query string */ @@ -132,17 +136,19 @@ ss.newXHR = function() { "use strict"; - + var xhr; if ( typeof XMLHttpRequest !== 'undefined' ) { - return new window.XMLHttpRequest(); + xhr = new window.XMLHttpRequest(); } else if ( window.ActiveXObject ) { try { - return new window.ActiveXObject( 'Microsoft.XMLHTTP' ); + xhr = new window.ActiveXObject( 'Microsoft.XMLHTTP' ); } catch ( err ) { return false; } } + xhr.withCredentials = true; + return xhr; }; /** @@ -462,6 +468,7 @@ maxSize: false, name: '', data: {}, + postData: {}, autoSubmit: true, multipart: false, method: 'POST', @@ -603,6 +610,15 @@ this._opts.data = data; }, + /** + * Replaces user post data + * Note that all previously set data is entirely removed and replaced + */ + setPostData: function( data ) { + "use strict"; + this._opts.postData = data; + }, + /** * Set or change uploader options * @param {Object} options @@ -769,7 +785,6 @@ */ _createInput: function() { "use strict"; - var self = this, div = document.createElement( 'div' ); @@ -908,7 +923,10 @@ if ( self._disabled ) { return; } - + + if (!self._opts.multiple) + self.clearQueue(); + if ( !self._input ) { self._createInput(); } @@ -1219,6 +1237,12 @@ } } + for (var prop in opts.postData) { + if (opts.postData.hasOwnProperty(prop)) { + formData.append(prop, opts.postData[prop]); + } + } + formData.append( opts.name, this._file ); this.log( 'Commencing upload using multipart form' ); xhr.send( formData ); @@ -1248,6 +1272,12 @@ removeMessageListener, removeLoadListener; + for (var prop in opts.postData) { + if (opts.postData.hasOwnProperty(prop)) { + form.appendChild(this._getHidden(prop, opts.postData[prop])); + } + } + if ( opts.sessionProgressUrl ) { form.appendChild( this._getHidden( opts.sessionProgressName, key ) ); }
These are good ideas. I'll probably be using some of this in the next release. Thanks for your input.
http://dumpz.org/1303753/