Merge branch 'bug-5735'

This commit is contained in:
jeresig 2009-12-31 14:49:01 -05:00
commit 40ce7f9830
4 changed files with 19 additions and 30 deletions

View file

@ -380,29 +380,21 @@ jQuery.extend({
} }
// Wait for a response to come back // Wait for a response to come back
var onreadystatechange = function( isTimeout ) { var onreadystatechange = xhr.onreadystatechange = function( isTimeout ) {
// The request was aborted, clear the interval and decrement jQuery.active // The request was aborted, clear the interval and decrement jQuery.active
if ( !xhr || xhr.readyState === 0 ) { if ( !xhr || xhr.readyState === 0 ) {
if ( ival ) { requestDone = true;
// clear poll interval xhr.onreadystatechange = jQuery.noop;
clearInterval( ival );
ival = null;
// Handle the global AJAX counter // Handle the global AJAX counter
if ( s.global && ! --jQuery.active ) { if ( s.global && ! --jQuery.active ) {
jQuery.event.trigger( "ajaxStop" ); jQuery.event.trigger( "ajaxStop" );
}
} }
// The transfer is complete and the data is available, or the request timed out // The transfer is complete and the data is available, or the request timed out
} else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) { } else if ( !requestDone && xhr && (xhr.readyState === 4 || isTimeout === "timeout") ) {
requestDone = true; requestDone = true;
xhr.onreadystatechange = jQuery.noop;
// clear poll interval
if (ival) {
clearInterval(ival);
ival = null;
}
status = isTimeout === "timeout" ? status = isTimeout === "timeout" ?
"timeout" : "timeout" :
@ -446,19 +438,14 @@ jQuery.extend({
} }
}; };
if ( s.async ) { // Timeout checker
// don't attach the handler to the request, just poll it instead if ( s.async && s.timeout > 0 ) {
var ival = setInterval(onreadystatechange, 13); setTimeout(function() {
// Check to see if the request is still happening
// Timeout checker if ( xhr && !requestDone ) {
if ( s.timeout > 0 ) { onreadystatechange( "timeout" );
setTimeout(function() { }
// Check to see if the request is still happening }, s.timeout);
if ( xhr && !requestDone ) {
onreadystatechange( "timeout" );
}
}, s.timeout);
}
} }
// Send the data // Send the data

View file

@ -464,6 +464,8 @@ jQuery.extend({
return true; return true;
}, },
noop: function() {},
// Evalulates a script in a global context // Evalulates a script in a global context
globalEval: function( data ) { globalEval: function( data ) {
if ( data && rnotwhite.test(data) ) { if ( data && rnotwhite.test(data) ) {

View file

@ -427,7 +427,7 @@ jQuery.event = {
ready: { ready: {
// Make sure the ready event is setup // Make sure the ready event is setup
setup: jQuery.bindReady, setup: jQuery.bindReady,
teardown: function() {} teardown: jQuery.noop
}, },
live: { live: {

View file

@ -121,7 +121,7 @@ jQuery.offset = {
body.removeChild( container ); body.removeChild( container );
body = container = innerDiv = checkDiv = table = td = null; body = container = innerDiv = checkDiv = table = td = null;
jQuery.offset.initialize = function() {}; jQuery.offset.initialize = jQuery.noop;
}, },
bodyOffset: function( body ) { bodyOffset: function( body ) {