- Timestamp:
- 05/04/12 18:00:28 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/prototype/plugins/fileupload/jquery.iframe-transport.js
r5341 r6107 1 1 /* 2 * jQuery Iframe Transport Plugin 1. 2.22 * jQuery Iframe Transport Plugin 1.4 3 3 * https://github.com/blueimp/jQuery-File-Upload 4 4 * … … 7 7 * 8 8 * Licensed under the MIT license: 9 * http:// creativecommons.org/licenses/MIT/9 * http://www.opensource.org/licenses/MIT 10 10 */ 11 11 12 /*jslint unparam: true */13 /*global jQuery*/12 /*jslint unparam: true, nomen: true */ 13 /*global define, window, document */ 14 14 15 (function ($) { 15 (function (factory) { 16 'use strict'; 17 if (typeof define === 'function' && define.amd) { 18 // Register as an anonymous AMD module: 19 define(['jquery'], factory); 20 } else { 21 // Browser globals: 22 factory(window.jQuery); 23 } 24 }(function ($) { 16 25 'use strict'; 17 26 … … 22 31 // options.fileInput: a jQuery collection of file input fields 23 32 // options.paramName: the parameter name for the file form data, 24 // overrides the name property of the file input field(s) 33 // overrides the name property of the file input field(s), 34 // can be a string or an array of strings. 25 35 // options.formData: an array of objects with name and value properties, 26 36 // equivalent to the return data of .serializeArray(), e.g.: 27 // [{name: a, value: 1}, {name: b, value: 2}]28 $.ajaxTransport('iframe', function (options , originalOptions, jqXHR) {29 if (options. type === 'POST' || options.type === 'GET') {37 // [{name: 'a', value: 1}, {name: 'b', value: 2}] 38 $.ajaxTransport('iframe', function (options) { 39 if (options.async && (options.type === 'POST' || options.type === 'GET')) { 30 40 var form, 31 41 iframe; 32 42 return { 33 send: function ( headers, completeCallback) {43 send: function (_, completeCallback) { 34 44 form = $('<form style="display:none;"></form>'); 35 45 // javascript:false as initial iframe src … … 42 52 (counter += 1) + '"></iframe>' 43 53 ).bind('load', function () { 44 var fileInputClones; 54 var fileInputClones, 55 paramNames = $.isArray(options.paramName) ? 56 options.paramName : [options.paramName]; 45 57 iframe 46 58 .unbind('load') … … 93 105 }); 94 106 if (options.paramName) { 95 options.fileInput.each(function () { 96 $(this).prop('name', options.paramName); 107 options.fileInput.each(function (index) { 108 $(this).prop( 109 'name', 110 paramNames[index] || options.paramName 111 ); 97 112 }); 98 113 } … … 116 131 } 117 132 }); 118 form.append(iframe).appendTo( 'body');133 form.append(iframe).appendTo(document.body); 119 134 }, 120 135 abort: function () { … … 140 155 converters: { 141 156 'iframe text': function (iframe) { 142 return iframe.text();157 return $(iframe[0].body).text(); 143 158 }, 144 159 'iframe json': function (iframe) { 145 return $.parseJSON( iframe.text());160 return $.parseJSON($(iframe[0].body).text()); 146 161 }, 147 162 'iframe html': function (iframe) { 148 return iframe.find('body').html();163 return $(iframe[0].body).html(); 149 164 }, 150 165 'iframe script': function (iframe) { 151 return $.globalEval( iframe.text());166 return $.globalEval($(iframe[0].body).text()); 152 167 } 153 168 } 154 169 }); 155 170 156 } (jQuery));171 }));
Note: See TracChangeset
for help on using the changeset viewer.