Commit f7ed2aca authored by jaubourg's avatar jaubourg

Removed re-usability from jXHR object (no more open, send & onreadystatechange...

Removed re-usability from jXHR object (no more open, send & onreadystatechange support). Streamlined the implementation and put it back into ajax.js (removed xhr.js in the process). Went back to a more simple & direct approach to options handling (keeping much room to further minification-related optimizations). Code is cleaner, smaller & faster. Removed & edited unit tests accordingly. All build files have had xhr.js removed.
parent 00fb8a9a
......@@ -24,7 +24,6 @@ BASE_FILES = ${SRC_DIR}/core.js\
${SRC_DIR}/manipulation.js\
${SRC_DIR}/css.js\
${SRC_DIR}/ajax.js\
${SRC_DIR}/xhr.js\
${SRC_DIR}/transports/jsonp.js\
${SRC_DIR}/transports/script.js\
${SRC_DIR}/transports/xhr.js\
......
......@@ -9,7 +9,7 @@ test_dir = File.join( prefix, 'test' )
# setting DIST_DIR before calling rake
dist_dir = ENV['DIST_DIR'] || File.join( prefix, 'dist' )
base_files = %w{intro core support data queue attributes event selector traversing manipulation css ajax xhr transports/jsonp transports/script transports/xhr effects offset dimensions outro}.map { |js| File.join( src_dir, "#{js}.js" ) }
base_files = %w{intro core support data queue attributes event selector traversing manipulation css ajax transports/jsonp transports/script transports/xhr effects offset dimensions outro}.map { |js| File.join( src_dir, "#{js}.js" ) }
# Sizzle, QUnit and jQuery files/dirs
sizzle_dir = File.join( src_dir, "sizzle" )
......
......@@ -63,7 +63,6 @@
<fileset file="src/manipulation.js" />
<fileset file="src/css.js" />
<fileset file="src/ajax.js" />
<fileset file="src/xhr.js" />
<fileset file="src/transports/jsonp.js" />
<fileset file="src/transports/script.js" />
<fileset file="src/transports/xhr.js" />
......
This diff is collapsed.
......@@ -14,7 +14,7 @@ jQuery.ajaxSettings.jsonpCallback = function() {
// 2) sneakily ensure transportDataType is json
// 3) ensure options jsonp is always provided so that jsonp requests are always
// json request with the jsonp option set
jQuery.xhr.prefilter("json jsonp", function(s) {
jQuery.ajax.prefilter("json jsonp", function(s) {
var transportDataType = s.dataTypes[ 0 ];
......
......@@ -17,7 +17,7 @@ jQuery.extend( true, jQuery.ajaxSettings , {
} );
// Bind script tag hack transport
jQuery.xhr.transport("script", function(s) {
jQuery.ajax.transport("script", function(s) {
// Handle cache special case
if ( s.cache === undefined ) {
......
......@@ -10,7 +10,7 @@ var // Next fake timer id
xhrUnloadAbortMarker = [];
jQuery.xhr.transport( function( s , determineDataType ) {
jQuery.ajax.transport( function( s , determineDataType ) {
// Cross domain only allowed if supported through XMLHttpRequest
if ( ! s.crossDomain || jQuery.support.cors ) {
......
This diff is collapsed.
......@@ -20,7 +20,6 @@
<script src="../src/manipulation.js"></script>
<script src="../src/css.js"></script>
<script src="../src/ajax.js"></script>
<script src="../src/xhr.js"></script>
<script src="../src/transports/jsonp.js"></script>
<script src="../src/transports/script.js"></script>
<script src="../src/transports/xhr.js"></script>
......
......@@ -74,7 +74,7 @@ test("jQuery.ajax() - success/error callbacks (remote)", function() {
var supports = jQuery.support.cors;
expect( supports ? 9 : 6 );
expect( supports ? 9 : 4 );
jQuery.ajaxSetup({ timeout: 0 });
......@@ -102,8 +102,8 @@ test("jQuery.ajax() - success/error callbacks (remote)", function() {
dataType: "text",
beforeSend: function(){ ok(supports, "beforeSend"); },
success: function( val ){ ok(supports, "success"); ok(supports && val.length, "data received"); },
error: function(_ , a , b ){ ok(!supports, "error"); },
complete: function(){ ok(true, "complete"); }
error: function(_ , a , b ){ ok(false, "error"); },
complete: function(){ ok(supports, "complete"); }
});
}, 13);
});
......@@ -409,136 +409,6 @@ test("jQuery.ajax() - abort", function() {
equals( xhr.readyState, 0, "XHR readyState indicates successful abortion" );
});
test("jQuery.ajax() - readyState (success)", function() {
expect( 1 );
jQuery.ajaxSetup({ timeout: 0 });
stop();
var control = "";
setTimeout(function(){
jQuery.ajax({
url: url("data/name.html"),
beforeSend: function( xhr ) {
xhr.onreadystatechange = function() {
control += xhr.readyState;
}
},
complete: function(){
setTimeout( function() {
equals( control , "1234" , "onreadystatechange was properly called" );
}, 13 );
start();
}
});
}, 13);
});
test("jQuery.ajax() - readyState (abort)", function() {
expect( 2 );
jQuery.ajaxSetup({ timeout: 0 });
stop();
var control = "";
setTimeout(function(){
jQuery.ajaxSetup({ timeout: 500 });
jQuery.ajax({
url: url("data/name.php?wait=5"),
beforeSend: function( xhr ) {
xhr.onreadystatechange = function() {
control += xhr.readyState;
}
},
complete: function( xhr ){
setTimeout( function() {
equals( control , "14" , "onreadystatechange was properly called" );
equals( xhr.readyState, 0 , "readyState is 0" );
}, 13 );
start();
}
});
}, 13);
});
test("jQuery.xhr() - reuse", function() {
expect( 15 );
jQuery.ajaxSetup({ timeout: 0 });
stop();
var number = 0;
setTimeout(function(){
jQuery('#foo').ajaxStart(function(){
ok( true, "ajaxStart" );
}).ajaxStop(function(){
ok( true, "ajaxStop" );
start();
}).ajaxSend(function(){
number++;
ok( true, "ajaxSend (" + number +")" );
}).ajaxComplete(function(){
ok( true, "ajaxComplete (" + number +")" );
}).ajaxError(function(){
ok( false, "ajaxError (" + number +")" );
}).ajaxSuccess(function(){
ok( true, "ajaxSuccess (" + number +")" );
});
jQuery.ajax({
url: url("data/name.html"),
beforeSend: function(){ ok(true, "beforeSend (1)"); },
success: function( _1 , _2 , xhr ){
ok(true, "success (1)");
xhr.complete(function() {
ok(true, "complete (1bis)");
});
xhr.open( "GET", url("data/name.html") );
xhr.success( function(){ ok(true, "beforeSend (2)"); } )
xhr.send( null, {
success: function(){ ok(true, "success (2)"); },
error: function(){ ok(false, "error (2)"); },
complete: function(){ ok(true, "complete (2)"); }
} );
},
error: function(){ ok(false, "error (1)"); },
complete: function(){ ok(true, "complete (1)"); }
});
}, 13);
});
test("jQuery.xhr() - early binding", function() {
expect( 2 );
jQuery.ajaxSetup({ timeout: 0 });
stop();
jQuery.xhr()
.success( function(){ ok(true, "success"); } )
.error( function(){ ok(false, "error"); } )
.complete( function(){ ok(true, "complete"); start(); } )
.open( "GET", url("data/name.html") )
.send();
});
test("jQuery.xhr() - get native implementation", function() {
var xhr = jQuery.xhr(true);
ok( xhr.readyState !== undefined , "implements XMLHttpRequest" );
ok( ! jQuery.isFunction( xhr.success ) , "is not jQuery's abstraction" );
});
test("Ajax events with context", function() {
expect(14);
......@@ -653,34 +523,6 @@ test("jQuery.ajax() - disabled globals", function() {
});
});
test("jQuery.xhr() - disabled globals through xhr.send(data , false)", function() {
expect( 2 );
stop();
jQuery('#foo').ajaxStart(function(){
ok( false, "ajaxStart" );
}).ajaxStop(function(){
ok( false, "ajaxStop" );
}).ajaxSend(function(){
ok( false, "ajaxSend" );
}).ajaxComplete(function(){
ok( false, "ajaxComplete" );
}).ajaxError(function(){
ok( false, "ajaxError" );
}).ajaxSuccess(function(){
ok( false, "ajaxSuccess" );
});
jQuery.xhr()
.success(function(){ ok(true, "success"); })
.error(function(){ ok(false, "error"); })
.complete(function(){
ok(true, "complete");
setTimeout(function(){ start(); }, 13);
})
.open("GET", url("data/name.html")).send(undefined, false);
});
test("jQuery.ajax - xml: non-namespace elements inside namespaced elements", function() {
expect(3);
stop();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment