Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

A little restructuring to allow more internal qunit tests to actually…

… run when media queries are supported.
  • Loading branch information...
commit e4dd82d47f52b5efcb888999d0677352eb161579 1 parent 744a9c6
@zachleat zachleat authored
Showing with 52 additions and 54 deletions.
  1. +44 −44 src/respond.js
  2. +8 −10 test/unit/tests.js
View
88 src/respond.js
@@ -10,13 +10,43 @@
//define update even in native-mq-supporting browsers, to avoid errors
respond.update = function(){};
- //expose media query support flag for external use
- respond.mediaQueriesSupported = w.matchMedia && w.matchMedia( "only all" ) !== null && w.matchMedia( "only all" ).matches;
+ //define ajax obj
+ var requestQueue = [],
+ xmlHttp = (function() {
+ var xmlhttpmethod = false;
+ try {
+ xmlhttpmethod = new w.XMLHttpRequest();
+ }
+ catch( e ){
+ xmlhttpmethod = new w.ActiveXObject( "Microsoft.XMLHTTP" );
+ }
+ return function(){
+ return xmlhttpmethod;
+ };
+ })(),
- //if media queries are supported, exit here
- if( respond.mediaQueriesSupported ){
- return;
- }
+ //tweaked Ajax functions from Quirksmode
+ ajax = function( url, callback ) {
+ var req = xmlHttp();
+ if (!req){
+ return;
+ }
+ req.open( "GET", url, true );
+ req.onreadystatechange = function () {
+ if ( req.readyState !== 4 || req.status !== 200 && req.status !== 304 ){
+ return;
+ }
+ callback( req.responseText );
+ };
+ if ( req.readyState === 4 ){
+ return;
+ }
+ req.send( null );
+ };
+
+ //expose for testing
+ respond.ajax = ajax;
+ respond.queue = requestQueue;
// expose for testing
respond.regex = {
@@ -29,6 +59,14 @@
maxw: /\(max\-width\s*:[\s]*([\s]*[0-9\.]+)(px|em)[\s]*\)/
};
+ //expose media query support flag for external use
+ respond.mediaQueriesSupported = w.matchMedia && w.matchMedia( "only all" ) !== null && w.matchMedia( "only all" ).matches;
+
+ //if media queries are supported, exit here
+ if( respond.mediaQueriesSupported ){
+ return;
+ }
+
//define vars
var doc = w.document,
docElem = doc.documentElement,
@@ -40,7 +78,6 @@
head = doc.getElementsByTagName( "head" )[0] || docElem,
base = doc.getElementsByTagName( "base" )[0],
links = head.getElementsByTagName( "link" ),
- requestQueue = [],
lastCall,
resizeDefer,
@@ -230,39 +267,6 @@
applyMedia();
},
- //define ajax obj
- xmlHttp = (function() {
- var xmlhttpmethod = false;
- try {
- xmlhttpmethod = new w.XMLHttpRequest();
- }
- catch( e ){
- xmlhttpmethod = new w.ActiveXObject( "Microsoft.XMLHTTP" );
- }
- return function(){
- return xmlhttpmethod;
- };
- })(),
-
- //tweaked Ajax functions from Quirksmode
- ajax = function( url, callback ) {
- var req = xmlHttp();
- if (!req){
- return;
- }
- req.open( "GET", url, true );
- req.onreadystatechange = function () {
- if ( req.readyState !== 4 || req.status !== 200 && req.status !== 304 ){
- return;
- }
- callback( req.responseText );
- };
- if ( req.readyState === 4 ){
- return;
- }
- req.send( null );
- },
-
//recurse through request queue, get css text
makeRequests = function(){
if( requestQueue.length ){
@@ -314,10 +318,6 @@
//translate CSS
ripCSS();
- //expose for testing
- respond.ajax = ajax;
- respond.queue = requestQueue;
-
//expose update for re-running respond later on
respond.update = ripCSS;
View
18 test/unit/tests.js
@@ -155,17 +155,15 @@ window.onload = function(){
});
// This test will only run on IE8 since the respond ajax stuff isn’t exposed yet
- if( ie <= 8 ) {
- asyncTest( 'Test keyframe animation inside of media query', function() {
- queueRequest( function() {
- respond.ajax( getNormalizedUrl( 'test-with-keyframe.css' ),
- function( data ) {
- ok( data.replace( respond.regex.keyframes ).match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ), 'A keyframe animation doesn\'t bust the media regex.' );
- start();
- });
- });
+ asyncTest( 'Test keyframe animation inside of media query', function() {
+ queueRequest( function() {
+ respond.ajax( getNormalizedUrl( 'test-with-keyframe.css' ),
+ function( data ) {
+ ok( data.replace( respond.regex.keyframes ).match( /@media[^\{]+\{([^\{\}]*\{[^\}\{]*\})+/gi ), 'A keyframe animation doesn\'t bust the media regex.' );
+ start();
+ });
});
- }
+ });
}
};
Please sign in to comment.
Something went wrong with that request. Please try again.