Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 12 additions & 5 deletions src/respond.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,10 +33,14 @@
}
req.open( "GET", url, true );
req.onreadystatechange = function () {
if ( req.readyState !== 4 || req.status !== 200 && req.status !== 304 ){
if ( req.readyState !== 4 ){
return;
}
callback( req.responseText );
if ( req.status !== 200 && req.status !== 304 ) {
callback(req);
return;
}
callback( null, req.responseText );
};
if ( req.readyState === 4 ){
return;
Expand Down Expand Up @@ -287,9 +291,12 @@
if( requestQueue.length ){
var thisRequest = requestQueue.shift();

ajax( thisRequest.href, function( styles ){
translate( styles, thisRequest.href, thisRequest.media );
parsedSheets[ thisRequest.href ] = true;
ajax( thisRequest.href, function( err, styles ){

if (! err) {
translate( styles, thisRequest.href, thisRequest.media );
parsedSheets[ thisRequest.href ] = true;
}

// by wrapping recursive function call in setTimeout
// we prevent "Stack overflow" error in IE7
Expand Down
1 change: 1 addition & 0 deletions test/unit/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
<link rel="stylesheet" href="qunit/qunit.css" media="screen">
<script src="qunit/qunit.js"></script>
<link href="test.css" rel="stylesheet" />
<link href="_fake.css" media="screen and (min-width: 68.75em)" rel="stylesheet" />
<link href="test2.css" media="screen and (min-width: 950px)" rel="stylesheet" />
<link href="test3.css" media="screen and (min-width: 68.75em)" rel="stylesheet" />
<script src="../../dest/respond.src.js"></script>
Expand Down
17 changes: 14 additions & 3 deletions test/unit/tests.js
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ window.onload = function(){
asyncTest( 'Test keyframe animation inside of media query', function() {
queueRequest( function() {
respond.ajax( getNormalizedUrl( 'test-with-keyframe.css' ),
function( data ) {
function( err, data ) {
ok( data.replace( respond.regex.keyframes, '' ).match( respond.regex.media ), 'A keyframe animation doesn\'t bust the media regex.' );
start();
});
Expand All @@ -169,7 +169,7 @@ window.onload = function(){
asyncTest( 'Test comments inside of a media query', function() {
queueRequest( function() {
respond.ajax( getNormalizedUrl( 'test-with-comment.css' ),
function( data ) {
function( err, data ) {
var stripped = data.replace( respond.regex.comments, '' );
// TODO allow /* */ inside of CSS content strings.
ok( stripped.match( respond.regex.media ), 'Comments don\'t bust the media regex.' );
Expand Down Expand Up @@ -247,12 +247,23 @@ window.onload = function(){
asyncTest( 'Issue #181: full MQ with DPR', function() {
queueRequest( function() {
respond.ajax( getNormalizedUrl( 'test-with-dpr.css' ),
function( data ) {
function( err, data ) {
ok( respond.unsupportedmq( data ) );
start();
});
});
});

asyncTest( 'Test ajax callback errors on 404', function() {
queueRequest( function() {
respond.ajax( 'does-not-exist',
function( err, data ) {
ok( err );
ok( ! data );
start();
});
});
});
}

};