mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
More improvements per @jaubourg
This commit is contained in:
parent
ad690f8151
commit
4ada325479
@ -160,34 +160,30 @@ function ajaxTest( title, expect, options ) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
var completed = false,
|
var completed = false,
|
||||||
|
remaining = requestOptions.length,
|
||||||
complete = function() {
|
complete = function() {
|
||||||
completed = true;
|
if ( !completed && --remaining === 0 ) {
|
||||||
delete ajaxTest.abort;
|
completed = true;
|
||||||
},
|
delete ajaxTest.abort;
|
||||||
abort = ajaxTest.abort = function( reason ) {
|
if ( options.teardown ) {
|
||||||
if ( !completed ) {
|
options.teardown();
|
||||||
complete();
|
}
|
||||||
ok( false, "unexpected " + reason );
|
start();
|
||||||
jQuery.each( requests, function( _, request ) {
|
|
||||||
if ( request && request.abort ) {
|
|
||||||
request.abort();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
requests = jQuery.map( requestOptions, function( options, index ) {
|
requests = jQuery.map( requestOptions, function( options ) {
|
||||||
var request = ( options.create || jQuery.ajax )( options ),
|
var request = ( options.create || jQuery.ajax )( options ),
|
||||||
callIfDefined = function( deferType, optionType ) {
|
callIfDefined = function( deferType, optionType ) {
|
||||||
var handler = options[ deferType ] || !!options[ optionType ];
|
var handler = options[ deferType ] || !!options[ optionType ];
|
||||||
return handler ?
|
return function( _, status ) {
|
||||||
function() {
|
if ( !completed ) {
|
||||||
if ( !completed && jQuery.isFunction( handler ) ) {
|
if ( !handler ) {
|
||||||
|
ok( false, "unexpected " + status );
|
||||||
|
} else if ( jQuery.isFunction( handler ) ) {
|
||||||
handler.apply( this, arguments );
|
handler.apply( this, arguments );
|
||||||
}
|
}
|
||||||
} :
|
}
|
||||||
function() {
|
};
|
||||||
abort( optionType );
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
if ( options.afterSend ) {
|
if ( options.afterSend ) {
|
||||||
@ -196,10 +192,20 @@ function ajaxTest( title, expect, options ) {
|
|||||||
|
|
||||||
return request
|
return request
|
||||||
.done( callIfDefined( "done", "success" ) )
|
.done( callIfDefined( "done", "success" ) )
|
||||||
.fail( callIfDefined( "fail", "error" ) );
|
.fail( callIfDefined( "fail", "error" ) )
|
||||||
|
.always( complete );
|
||||||
});
|
});
|
||||||
|
|
||||||
jQuery.when.apply( jQuery, requests ).always( complete, options.teardown, start);
|
ajaxTest.abort = function( reason ) {
|
||||||
|
if ( !completed ) {
|
||||||
|
completed = true;
|
||||||
|
delete ajaxTest.abort;
|
||||||
|
ok( false, "aborted " + reason );
|
||||||
|
jQuery.each( requests, function( i, request ) {
|
||||||
|
request.abort();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -310,7 +310,7 @@ var Globals = (function() {
|
|||||||
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
|
if ( jQuery.active !== undefined && jQuery.active !== oldActive ) {
|
||||||
equal( jQuery.active, 0, "No AJAX requests are still active" );
|
equal( jQuery.active, 0, "No AJAX requests are still active" );
|
||||||
if ( ajaxTest.abort ) {
|
if ( ajaxTest.abort ) {
|
||||||
ajaxTest.abort("active request");
|
ajaxTest.abort("active requests");
|
||||||
}
|
}
|
||||||
oldActive = jQuery.active;
|
oldActive = jQuery.active;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user