Update JQuery Form to version 3.18
This commit is contained in:
parent
7335bf06a8
commit
aa8c854016
@ -1,7 +1,7 @@
|
||||
/*!
|
||||
* jQuery Form Plugin
|
||||
* version: 3.14 (30-JUL-2012)
|
||||
* @requires jQuery v1.3.2 or later
|
||||
* version: 3.18 (28-SEP-2012)
|
||||
* @requires jQuery v1.5 or later
|
||||
*
|
||||
* Examples and documentation at: http://malsup.com/jquery/form/
|
||||
* Project repository: https://github.com/malsup/form
|
||||
@ -181,6 +181,8 @@ $.fn.ajaxSubmit = function(options) {
|
||||
log("fileAPI :" + fileAPI);
|
||||
var shouldUseFrame = (hasFileInputs || multipart) && !fileAPI;
|
||||
|
||||
var jqxhr;
|
||||
|
||||
// options.iframe allows user to force iframe mode
|
||||
// 06-NOV-09: now defaulting to iframe mode if file input is detected
|
||||
if (options.iframe !== false && (options.iframe || shouldUseFrame)) {
|
||||
@ -188,20 +190,22 @@ $.fn.ajaxSubmit = function(options) {
|
||||
// see: http://groups.google.com/group/jquery-dev/browse_thread/thread/36395b7ab510dd5d
|
||||
if (options.closeKeepAlive) {
|
||||
$.get(options.closeKeepAlive, function() {
|
||||
fileUploadIframe(a);
|
||||
jqxhr = fileUploadIframe(a);
|
||||
});
|
||||
}
|
||||
else {
|
||||
fileUploadIframe(a);
|
||||
}
|
||||
else {
|
||||
jqxhr = fileUploadIframe(a);
|
||||
}
|
||||
}
|
||||
else if ((hasFileInputs || multipart) && fileAPI) {
|
||||
fileUploadXhr(a);
|
||||
jqxhr = fileUploadXhr(a);
|
||||
}
|
||||
else {
|
||||
$.ajax(options);
|
||||
jqxhr = $.ajax(options);
|
||||
}
|
||||
|
||||
$form.removeData('jqxhr').data('jqxhr', jqxhr);
|
||||
|
||||
// clear element array
|
||||
for (var k=0; k < elements.length; k++)
|
||||
elements[k] = null;
|
||||
@ -210,6 +214,19 @@ $.fn.ajaxSubmit = function(options) {
|
||||
this.trigger('form-submit-notify', [this, options]);
|
||||
return this;
|
||||
|
||||
// utility fn for deep serialization
|
||||
function deepSerialize(extraData){
|
||||
var serialized = $.param(extraData).split('&');
|
||||
var len = serialized.length;
|
||||
var result = {};
|
||||
var i, part;
|
||||
for (i=0; i < len; i++) {
|
||||
part = serialized[i].split('=');
|
||||
result[decodeURIComponent(part[0])] = decodeURIComponent(part[1]);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
// XMLHttpRequest Level 2 file uploads (big hat tip to francois2metz)
|
||||
function fileUploadXhr(a) {
|
||||
var formdata = new FormData();
|
||||
@ -219,9 +236,10 @@ $.fn.ajaxSubmit = function(options) {
|
||||
}
|
||||
|
||||
if (options.extraData) {
|
||||
for (var p in options.extraData)
|
||||
if (options.extraData.hasOwnProperty(p))
|
||||
formdata.append(p, options.extraData[p]);
|
||||
var serializedData = deepSerialize(options.extraData);
|
||||
for (var p in serializedData)
|
||||
if (serializedData.hasOwnProperty(p))
|
||||
formdata.append(p, serializedData[p]);
|
||||
}
|
||||
|
||||
options.data = null;
|
||||
@ -230,7 +248,7 @@ $.fn.ajaxSubmit = function(options) {
|
||||
contentType: false,
|
||||
processData: false,
|
||||
cache: false,
|
||||
type: 'POST'
|
||||
type: method || 'POST'
|
||||
});
|
||||
|
||||
if (options.uploadProgress) {
|
||||
@ -259,19 +277,21 @@ $.fn.ajaxSubmit = function(options) {
|
||||
if(beforeSend)
|
||||
beforeSend.call(this, xhr, o);
|
||||
};
|
||||
$.ajax(s);
|
||||
return $.ajax(s);
|
||||
}
|
||||
|
||||
// private function for handling file uploads (hat tip to YAHOO!)
|
||||
function fileUploadIframe(a) {
|
||||
var form = $form[0], el, i, s, g, id, $io, io, xhr, sub, n, timedOut, timeoutHandle;
|
||||
var useProp = !!$.fn.prop;
|
||||
var deferred = $.Deferred();
|
||||
|
||||
if ($(':input[name=submit],:input[id=submit]', form).length) {
|
||||
// if there is an input with a name or id of 'submit' then we won't be
|
||||
// able to invoke the submit fn on the form (at least not x-browser)
|
||||
alert('Error: Form elements must not have name or id of "submit".');
|
||||
return;
|
||||
deferred.reject();
|
||||
return deferred;
|
||||
}
|
||||
|
||||
if (a) {
|
||||
@ -346,10 +366,12 @@ $.fn.ajaxSubmit = function(options) {
|
||||
if (s.global) {
|
||||
$.active--;
|
||||
}
|
||||
return;
|
||||
deferred.reject();
|
||||
return deferred;
|
||||
}
|
||||
if (xhr.aborted) {
|
||||
return;
|
||||
deferred.reject();
|
||||
return deferred;
|
||||
}
|
||||
|
||||
// add submitting element to data if we know it
|
||||
@ -491,10 +513,12 @@ $.fn.ajaxSubmit = function(options) {
|
||||
}
|
||||
if (e === CLIENT_TIMEOUT_ABORT && xhr) {
|
||||
xhr.abort('timeout');
|
||||
deferred.reject(xhr, 'timeout');
|
||||
return;
|
||||
}
|
||||
else if (e == SERVER_ABORT && xhr) {
|
||||
xhr.abort('server abort');
|
||||
deferred.reject(xhr, 'error', 'server abort');
|
||||
return;
|
||||
}
|
||||
|
||||
@ -599,6 +623,7 @@ $.fn.ajaxSubmit = function(options) {
|
||||
if (status === 'success') {
|
||||
if (s.success)
|
||||
s.success.call(s.context, data, 'success', xhr);
|
||||
deferred.resolve(xhr.responseText, 'success', xhr);
|
||||
if (g)
|
||||
$.event.trigger("ajaxSuccess", [xhr, s]);
|
||||
}
|
||||
@ -607,6 +632,7 @@ $.fn.ajaxSubmit = function(options) {
|
||||
errMsg = xhr.statusText;
|
||||
if (s.error)
|
||||
s.error.call(s.context, xhr, status, errMsg);
|
||||
deferred.reject(xhr, 'error', errMsg);
|
||||
if (g)
|
||||
$.event.trigger("ajaxError", [xhr, s, errMsg]);
|
||||
}
|
||||
@ -671,6 +697,8 @@ $.fn.ajaxSubmit = function(options) {
|
||||
}
|
||||
return data;
|
||||
};
|
||||
|
||||
return deferred;
|
||||
}
|
||||
};
|
||||
|
||||
@ -1086,4 +1114,4 @@ function log() {
|
||||
}
|
||||
}
|
||||
|
||||
})(jQuery);
|
||||
})(jQuery);
|
||||
|
Loading…
Reference in New Issue
Block a user