|
1 | 1 | /*
|
2 |
| - * jQuery Iframe Transport Plugin 1.6.2 |
| 2 | + * jQuery Iframe Transport Plugin 1.8.2 |
3 | 3 | * https://github.com/blueimp/jQuery-File-Upload
|
4 | 4 | *
|
5 | 5 | * Copyright 2011, Sebastian Tschan
|
|
9 | 9 | * http://www.opensource.org/licenses/MIT
|
10 | 10 | */
|
11 | 11 |
|
12 |
| -/*jslint unparam: true, nomen: true */ |
13 |
| -/*global define, window, document */ |
| 12 | +/* global define, window, document */ |
14 | 13 |
|
15 | 14 | (function (factory) {
|
16 | 15 | 'use strict';
|
|
27 | 26 | // Helper variable to create unique names for the transport iframes:
|
28 | 27 | var counter = 0;
|
29 | 28 |
|
30 |
| - // The iframe transport accepts three additional options: |
| 29 | + // The iframe transport accepts four additional options: |
31 | 30 | // options.fileInput: a jQuery collection of file input fields
|
32 | 31 | // options.paramName: the parameter name for the file form data,
|
33 | 32 | // overrides the name property of the file input field(s),
|
34 | 33 | // can be a string or an array of strings.
|
35 | 34 | // options.formData: an array of objects with name and value properties,
|
36 | 35 | // equivalent to the return data of .serializeArray(), e.g.:
|
37 | 36 | // [{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;" |
38 | 39 | $.ajaxTransport('iframe', function (options) {
|
39 | 40 | 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, |
41 | 47 | iframe,
|
42 | 48 | addParamChar;
|
43 | 49 | return {
|
|
56 | 62 | options.url = options.url + addParamChar + '_method=PATCH';
|
57 | 63 | options.type = 'POST';
|
58 | 64 | }
|
59 |
| - // javascript:false as initial iframe src |
60 |
| - // prevents warning popups on HTTPS in IE6. |
61 | 65 | // IE versions below IE8 cannot set the name property of
|
62 | 66 | // elements that have already been added to the DOM,
|
63 | 67 | // so we set the name along with the iframe HTML markup:
|
64 | 68 | counter += 1;
|
65 | 69 | iframe = $(
|
66 |
| - '<iframe src="javascript:false;" name="iframe-transport-' + |
67 |
| - counter + '"></iframe>' |
| 70 | + '<iframe src="' + initialIframeSrc + |
| 71 | + '" name="iframe-transport-' + counter + '"></iframe>' |
68 | 72 | ).bind('load', function () {
|
69 | 73 | var fileInputClones,
|
70 | 74 | paramNames = $.isArray(options.paramName) ?
|
|
95 | 99 | );
|
96 | 100 | // Fix for IE endless progress bar activity bug
|
97 | 101 | // (happens on form submits to iframe targets):
|
98 |
| - $('<iframe src="javascript:false;"></iframe>') |
| 102 | + $('<iframe src="' + initialIframeSrc + '"></iframe>') |
99 | 103 | .appendTo(form);
|
100 | 104 | window.setTimeout(function () {
|
101 | 105 | // Removing the form in a setTimeout call
|
|
138 | 142 | .prop('enctype', 'multipart/form-data')
|
139 | 143 | // enctype must be set as encoding for IE:
|
140 | 144 | .prop('encoding', 'multipart/form-data');
|
| 145 | + // Remove the HTML5 form attribute from the input(s): |
| 146 | + options.fileInput.removeAttr('form'); |
141 | 147 | }
|
142 | 148 | form.submit();
|
143 | 149 | // Insert the file input fields at their original location
|
144 | 150 | // by replacing the clones with the originals:
|
145 | 151 | if (fileInputClones && fileInputClones.length) {
|
146 | 152 | options.fileInput.each(function (index, input) {
|
147 | 153 | 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')); |
149 | 158 | clone.replaceWith(input);
|
150 | 159 | });
|
151 | 160 | }
|
|
159 | 168 | // concat is used to avoid the "Script URL" JSLint error:
|
160 | 169 | iframe
|
161 | 170 | .unbind('load')
|
162 |
| - .prop('src', 'javascript'.concat(':false;')); |
| 171 | + .prop('src', initialIframeSrc); |
163 | 172 | }
|
164 | 173 | if (form) {
|
165 | 174 | form.remove();
|
|
170 | 179 | });
|
171 | 180 |
|
172 | 181 | // 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 |
174 | 191 | $.ajaxSetup({
|
175 | 192 | converters: {
|
176 | 193 | 'iframe text': function (iframe) {
|
|
182 | 199 | 'iframe html': function (iframe) {
|
183 | 200 | return iframe && $(iframe[0].body).html();
|
184 | 201 | },
|
| 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 | + }, |
185 | 208 | 'iframe script': function (iframe) {
|
186 | 209 | return iframe && $.globalEval($(iframe[0].body).text());
|
187 | 210 | }
|
|
0 commit comments