forked from GNUsocial/gnu-social
Update jquery.form.js to 2.63 -- 2.60 fixed our Opera regression per issue #3015
Thanks to the fine folks at http://forum.jquery.com/topic/regression-form-plugin-ajaxform-cannot-access-xml-return-data-in-opera#14737000001950332 :D
This commit is contained in:
parent
ea4ebe280a
commit
b2f4a02377
@ -1,6 +1,6 @@
|
|||||||
/*!
|
/*!
|
||||||
* jQuery Form Plugin
|
* jQuery Form Plugin
|
||||||
* version: 2.49 (18-OCT-2010)
|
* version: 2.63 (29-JAN-2011)
|
||||||
* @requires jQuery v1.3.2 or later
|
* @requires jQuery v1.3.2 or later
|
||||||
*
|
*
|
||||||
* Examples and documentation at: http://malsup.com/jquery/form/
|
* Examples and documentation at: http://malsup.com/jquery/form/
|
||||||
@ -54,7 +54,8 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
options = { success: options };
|
options = { success: options };
|
||||||
}
|
}
|
||||||
|
|
||||||
var url = $.trim(this.attr('action'));
|
var action = this.attr('action');
|
||||||
|
var url = (typeof action === 'string') ? $.trim(action) : '';
|
||||||
if (url) {
|
if (url) {
|
||||||
// clean url (don't include hash vaue)
|
// clean url (don't include hash vaue)
|
||||||
url = (url.match(/^([^#]+)/)||[])[1];
|
url = (url.match(/^([^#]+)/)||[])[1];
|
||||||
@ -63,7 +64,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
|
|
||||||
options = $.extend(true, {
|
options = $.extend(true, {
|
||||||
url: url,
|
url: url,
|
||||||
type: this.attr('method') || 'GET',
|
type: this[0].getAttribute('method') || 'GET', // IE7 massage (see issue 57)
|
||||||
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
|
iframeSrc: /^https/i.test(window.location.href || '') ? 'javascript:false' : 'about:blank'
|
||||||
}, options);
|
}, options);
|
||||||
|
|
||||||
@ -167,7 +168,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
$.ajax(options);
|
$.ajax(options);
|
||||||
}
|
}
|
||||||
|
|
||||||
// fire 'notify' event
|
// fire 'notify' event
|
||||||
@ -189,15 +190,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
var s = $.extend(true, {}, $.ajaxSettings, options);
|
var s = $.extend(true, {}, $.ajaxSettings, options);
|
||||||
s.context = s.context || s;
|
s.context = s.context || s;
|
||||||
var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id;
|
var id = 'jqFormIO' + (new Date().getTime()), fn = '_'+id;
|
||||||
window[fn] = function() {
|
var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" />');
|
||||||
var f = $io.data('form-plugin-onload');
|
|
||||||
if (f) {
|
|
||||||
f();
|
|
||||||
window[fn] = undefined;
|
|
||||||
try { delete window[fn]; } catch(e){}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
var $io = $('<iframe id="' + id + '" name="' + id + '" src="'+ s.iframeSrc +'" onload="window[\'_\'+this.id]()" />');
|
|
||||||
var io = $io[0];
|
var io = $io[0];
|
||||||
|
|
||||||
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
$io.css({ position: 'absolute', top: '-1000px', left: '-1000px' });
|
||||||
@ -236,7 +229,6 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
var cbInvoked = false;
|
|
||||||
var timedOut = 0;
|
var timedOut = 0;
|
||||||
|
|
||||||
// add submitting element to data if we know it
|
// add submitting element to data if we know it
|
||||||
@ -293,7 +285,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
|
|
||||||
// add iframe to doc and submit the form
|
// add iframe to doc and submit the form
|
||||||
$io.appendTo('body');
|
$io.appendTo('body');
|
||||||
$io.data('form-plugin-onload', cb);
|
io.attachEvent ? io.attachEvent('onload', cb) : io.addEventListener('load', cb, false);
|
||||||
form.submit();
|
form.submit();
|
||||||
}
|
}
|
||||||
finally {
|
finally {
|
||||||
@ -318,19 +310,18 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
var data, doc, domCheckCount = 50;
|
var data, doc, domCheckCount = 50;
|
||||||
|
|
||||||
function cb() {
|
function cb() {
|
||||||
if (cbInvoked) {
|
doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
|
||||||
|
if (!doc || doc.location.href == s.iframeSrc) {
|
||||||
|
// response not received yet
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
io.detachEvent ? io.detachEvent('onload', cb) : io.removeEventListener('load', cb, false);
|
||||||
$io.removeData('form-plugin-onload');
|
|
||||||
|
|
||||||
var ok = true;
|
var ok = true;
|
||||||
try {
|
try {
|
||||||
if (timedOut) {
|
if (timedOut) {
|
||||||
throw 'timeout';
|
throw 'timeout';
|
||||||
}
|
}
|
||||||
// extract the server response from the iframe
|
|
||||||
doc = io.contentWindow ? io.contentWindow.document : io.contentDocument ? io.contentDocument : io.document;
|
|
||||||
|
|
||||||
var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
|
var isXml = s.dataType == 'xml' || doc.XMLDocument || $.isXMLDoc(doc);
|
||||||
log('isXml='+isXml);
|
log('isXml='+isXml);
|
||||||
@ -348,8 +339,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//log('response detected');
|
//log('response detected');
|
||||||
cbInvoked = true;
|
xhr.responseText = doc.body ? doc.body.innerHTML : doc.documentElement ? doc.documentElement.innerHTML : null;
|
||||||
xhr.responseText = doc.documentElement ? doc.documentElement.innerHTML : null;
|
|
||||||
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
xhr.responseXML = doc.XMLDocument ? doc.XMLDocument : doc;
|
||||||
xhr.getResponseHeader = function(header){
|
xhr.getResponseHeader = function(header){
|
||||||
var headers = {'content-type': s.dataType};
|
var headers = {'content-type': s.dataType};
|
||||||
@ -368,7 +358,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
var pre = doc.getElementsByTagName('pre')[0];
|
var pre = doc.getElementsByTagName('pre')[0];
|
||||||
var b = doc.getElementsByTagName('body')[0];
|
var b = doc.getElementsByTagName('body')[0];
|
||||||
if (pre) {
|
if (pre) {
|
||||||
xhr.responseText = pre.innerHTML;
|
xhr.responseText = pre.textContent;
|
||||||
}
|
}
|
||||||
else if (b) {
|
else if (b) {
|
||||||
xhr.responseText = b.innerHTML;
|
xhr.responseText = b.innerHTML;
|
||||||
@ -378,31 +368,35 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
|
else if (s.dataType == 'xml' && !xhr.responseXML && xhr.responseText != null) {
|
||||||
xhr.responseXML = toXml(xhr.responseText);
|
xhr.responseXML = toXml(xhr.responseText);
|
||||||
}
|
}
|
||||||
data = $.httpData(xhr, s.dataType);
|
|
||||||
|
data = httpData(xhr, s.dataType, s);
|
||||||
}
|
}
|
||||||
catch(e){
|
catch(e){
|
||||||
log('error caught:',e);
|
log('error caught:',e);
|
||||||
ok = false;
|
ok = false;
|
||||||
xhr.error = e;
|
xhr.error = e;
|
||||||
$.handleError(s, xhr, 'error', e);
|
s.error.call(s.context, xhr, 'error', e);
|
||||||
|
g && $.event.trigger("ajaxError", [xhr, s, e]);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (xhr.aborted) {
|
||||||
|
log('upload aborted');
|
||||||
|
ok = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
// ordering of these callbacks/triggers is odd, but that's how $.ajax does it
|
||||||
if (ok) {
|
if (ok) {
|
||||||
s.success.call(s.context, data, 'success', xhr);
|
s.success.call(s.context, data, 'success', xhr);
|
||||||
if (g) {
|
g && $.event.trigger("ajaxSuccess", [xhr, s]);
|
||||||
$.event.trigger("ajaxSuccess", [xhr, s]);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (g) {
|
|
||||||
$.event.trigger("ajaxComplete", [xhr, s]);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
g && $.event.trigger("ajaxComplete", [xhr, s]);
|
||||||
|
|
||||||
if (g && ! --$.active) {
|
if (g && ! --$.active) {
|
||||||
$.event.trigger("ajaxStop");
|
$.event.trigger("ajaxStop");
|
||||||
}
|
}
|
||||||
if (s.complete) {
|
|
||||||
s.complete.call(s.context, xhr, ok ? 'success' : 'error');
|
s.complete && s.complete.call(s.context, xhr, ok ? 'success' : 'error');
|
||||||
}
|
|
||||||
|
|
||||||
// clean up
|
// clean up
|
||||||
setTimeout(function() {
|
setTimeout(function() {
|
||||||
@ -412,7 +406,7 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
}, 100);
|
}, 100);
|
||||||
}
|
}
|
||||||
|
|
||||||
function toXml(s, doc) {
|
var toXml = $.parseXML || function(s, doc) { // use parseXML if available (jQuery 1.5+)
|
||||||
if (window.ActiveXObject) {
|
if (window.ActiveXObject) {
|
||||||
doc = new ActiveXObject('Microsoft.XMLDOM');
|
doc = new ActiveXObject('Microsoft.XMLDOM');
|
||||||
doc.async = 'false';
|
doc.async = 'false';
|
||||||
@ -421,8 +415,32 @@ $.fn.ajaxSubmit = function(options) {
|
|||||||
else {
|
else {
|
||||||
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
doc = (new DOMParser()).parseFromString(s, 'text/xml');
|
||||||
}
|
}
|
||||||
return (doc && doc.documentElement && doc.documentElement.tagName != 'parsererror') ? doc : null;
|
return (doc && doc.documentElement && doc.documentElement.nodeName != 'parsererror') ? doc : null;
|
||||||
}
|
};
|
||||||
|
var parseJSON = $.parseJSON || function(s) {
|
||||||
|
return window['eval']('(' + s + ')');
|
||||||
|
};
|
||||||
|
|
||||||
|
var httpData = function( xhr, type, s ) { // mostly lifted from jq1.4.4
|
||||||
|
var ct = xhr.getResponseHeader('content-type') || '',
|
||||||
|
xml = type === 'xml' || !type && ct.indexOf('xml') >= 0,
|
||||||
|
data = xml ? xhr.responseXML : xhr.responseText;
|
||||||
|
|
||||||
|
if (xml && data.documentElement.nodeName === 'parsererror') {
|
||||||
|
$.error && $.error('parsererror');
|
||||||
|
}
|
||||||
|
if (s && s.dataFilter) {
|
||||||
|
data = s.dataFilter(data, type);
|
||||||
|
}
|
||||||
|
if (typeof data === 'string') {
|
||||||
|
if (type === 'json' || !type && ct.indexOf('json') >= 0) {
|
||||||
|
data = parseJSON(data);
|
||||||
|
} else if (type === "script" || !type && ct.indexOf("javascript") >= 0) {
|
||||||
|
$.globalEval(data);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return data;
|
||||||
|
};
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
4
js/jquery.form.min.js
vendored
4
js/jquery.form.min.js
vendored
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue
Block a user