Index SimpleAjaxUploader js --- SimpleAjaxUploader js revision 121436

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
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 ) );
}