Skip to content

Commit 44b3b7a

Browse files
committed
Update jQuery Iframe Transport Plugin to 1.8.2
1 parent 3d250be commit 44b3b7a

File tree

1 file changed

+36
-13
lines changed

1 file changed

+36
-13
lines changed

vendor/assets/javascripts/jquery-fileupload/jquery.iframe-transport.js

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* jQuery Iframe Transport Plugin 1.6.2
2+
* jQuery Iframe Transport Plugin 1.8.2
33
* https://github.com/blueimp/jQuery-File-Upload
44
*
55
* Copyright 2011, Sebastian Tschan
@@ -9,8 +9,7 @@
99
* http://www.opensource.org/licenses/MIT
1010
*/
1111

12-
/*jslint unparam: true, nomen: true */
13-
/*global define, window, document */
12+
/* global define, window, document */
1413

1514
(function (factory) {
1615
'use strict';
@@ -27,17 +26,24 @@
2726
// Helper variable to create unique names for the transport iframes:
2827
var counter = 0;
2928

30-
// The iframe transport accepts three additional options:
29+
// The iframe transport accepts four additional options:
3130
// options.fileInput: a jQuery collection of file input fields
3231
// options.paramName: the parameter name for the file form data,
3332
// overrides the name property of the file input field(s),
3433
// can be a string or an array of strings.
3534
// options.formData: an array of objects with name and value properties,
3635
// equivalent to the return data of .serializeArray(), e.g.:
3736
// [{name: 'a', value: 1}, {name: 'b', value: 2}]
37+
// options.initialIframeSrc: the URL of the initial iframe src,
38+
// by default set to "javascript:false;"
3839
$.ajaxTransport('iframe', function (options) {
3940
if (options.async) {
40-
var form,
41+
// javascript:false as initial iframe src
42+
// prevents warning popups on HTTPS in IE6:
43+
/*jshint scripturl: true */
44+
var initialIframeSrc = options.initialIframeSrc || 'javascript:false;',
45+
/*jshint scripturl: false */
46+
form,
4147
iframe,
4248
addParamChar;
4349
return {
@@ -56,15 +62,13 @@
5662
options.url = options.url + addParamChar + '_method=PATCH';
5763
options.type = 'POST';
5864
}
59-
// javascript:false as initial iframe src
60-
// prevents warning popups on HTTPS in IE6.
6165
// IE versions below IE8 cannot set the name property of
6266
// elements that have already been added to the DOM,
6367
// so we set the name along with the iframe HTML markup:
6468
counter += 1;
6569
iframe = $(
66-
'<iframe src="javascript:false;" name="iframe-transport-' +
67-
counter + '"></iframe>'
70+
'<iframe src="' + initialIframeSrc +
71+
'" name="iframe-transport-' + counter + '"></iframe>'
6872
).bind('load', function () {
6973
var fileInputClones,
7074
paramNames = $.isArray(options.paramName) ?
@@ -95,7 +99,7 @@
9599
);
96100
// Fix for IE endless progress bar activity bug
97101
// (happens on form submits to iframe targets):
98-
$('<iframe src="javascript:false;"></iframe>')
102+
$('<iframe src="' + initialIframeSrc + '"></iframe>')
99103
.appendTo(form);
100104
window.setTimeout(function () {
101105
// Removing the form in a setTimeout call
@@ -138,14 +142,19 @@
138142
.prop('enctype', 'multipart/form-data')
139143
// enctype must be set as encoding for IE:
140144
.prop('encoding', 'multipart/form-data');
145+
// Remove the HTML5 form attribute from the input(s):
146+
options.fileInput.removeAttr('form');
141147
}
142148
form.submit();
143149
// Insert the file input fields at their original location
144150
// by replacing the clones with the originals:
145151
if (fileInputClones && fileInputClones.length) {
146152
options.fileInput.each(function (index, input) {
147153
var clone = $(fileInputClones[index]);
148-
$(input).prop('name', clone.prop('name'));
154+
// Restore the original name and form properties:
155+
$(input)
156+
.prop('name', clone.prop('name'))
157+
.attr('form', clone.attr('form'));
149158
clone.replaceWith(input);
150159
});
151160
}
@@ -159,7 +168,7 @@
159168
// concat is used to avoid the "Script URL" JSLint error:
160169
iframe
161170
.unbind('load')
162-
.prop('src', 'javascript'.concat(':false;'));
171+
.prop('src', initialIframeSrc);
163172
}
164173
if (form) {
165174
form.remove();
@@ -170,7 +179,15 @@
170179
});
171180

172181
// The iframe transport returns the iframe content document as response.
173-
// The following adds converters from iframe to text, json, html, and script:
182+
// The following adds converters from iframe to text, json, html, xml
183+
// and script.
184+
// Please note that the Content-Type for JSON responses has to be text/plain
185+
// or text/html, if the browser doesn't include application/json in the
186+
// Accept header, else IE will show a download dialog.
187+
// The Content-Type for XML responses on the other hand has to be always
188+
// application/xml or text/xml, so IE properly parses the XML response.
189+
// See also
190+
// https://github.com/blueimp/jQuery-File-Upload/wiki/Setup#content-type-negotiation
174191
$.ajaxSetup({
175192
converters: {
176193
'iframe text': function (iframe) {
@@ -182,6 +199,12 @@
182199
'iframe html': function (iframe) {
183200
return iframe && $(iframe[0].body).html();
184201
},
202+
'iframe xml': function (iframe) {
203+
var xmlDoc = iframe && iframe[0];
204+
return xmlDoc && $.isXMLDoc(xmlDoc) ? xmlDoc :
205+
$.parseXML((xmlDoc.XMLDocument && xmlDoc.XMLDocument.xml) ||
206+
$(xmlDoc.body).html());
207+
},
185208
'iframe script': function (iframe) {
186209
return iframe && $.globalEval($(iframe[0].body).text());
187210
}

0 commit comments

Comments
 (0)