Permalink
Browse files

rough pass at em unit support in media queries

  • Loading branch information...
1 parent e27112a commit 2ad79c9a59e7dd2c2d9a4774db3407b7ef593fac scottjehl committed Sep 23, 2011
Showing with 26 additions and 10 deletions.
  1. +1 −1 respond.min.js
  2. +25 −9 respond.src.js
View

Some generated files are not rendered by default. Learn more.

Oops, something went wrong.
View
@@ -114,15 +114,14 @@
eachq = fullq.split( "," );
eql = eachq.length;
-
for( ; j < eql; j++ ){
thisq = eachq[ j ];
mediastyles.push( {
media : thisq.match( /(only\s+)?([a-zA-Z]+)(\sand)?/ ) && RegExp.$2,
rules : rules.length - 1,
- minw : thisq.match( /\(min\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/ ) && parseFloat( RegExp.$1 ),
- maxw : thisq.match( /\(max\-width:[\s]*([\s]*[0-9]+)px[\s]*\)/ ) && parseFloat( RegExp.$1 )
+ minw : thisq.match( /\(min\-width:[\s]*([\s]*[0-9]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" ),
+ maxw : thisq.match( /\(max\-width:[\s]*([\s]*[0-9]+)(px|em)[\s]*\)/ ) && parseFloat( RegExp.$1 ) + ( RegExp.$2 || "" )
} );
}
}
@@ -142,8 +141,9 @@
styleBlocks = {},
dFrag = doc.createDocumentFragment(),
lastLink = links[ links.length-1 ],
- now = (new Date()).getTime();
-
+ now = (new Date()).getTime(),
+ eminpx = parseFloat( docElem.currentStyle ? body.currentStyle.fontSize : document.defaultView.getComputedStyle( body, null ).getPropertyValue( "font-size" ) );
+
//throttle resize calls
if( fromResize && lastCall && now - lastCall < resizeThrottle ){
clearTimeout( resizeDefer );
@@ -155,10 +155,26 @@
}
for( var i in mediastyles ){
- var thisstyle = mediastyles[ i ];
- if( !thisstyle.minw && !thisstyle.maxw ||
- ( !thisstyle.minw || thisstyle.minw && currWidth >= thisstyle.minw ) &&
- (!thisstyle.maxw || thisstyle.maxw && currWidth <= thisstyle.maxw ) ){
+ var thisstyle = mediastyles[ i ],
+ min = thisstyle.minw,
+ max = thisstyle.maxw;
+
+ if( min ){
+ min = min.replace( "px", "" );
+ if( min.indexOf( "em" ) ){
+ min = parseFloat( min.replace( "em", "" ) ) * eminpx;
+ }
+ }
+ if( max ){
+ max = max.replace( "px", "" );
+ if( max.indexOf( "em" ) ){
+ max = parseFloat( max.replace( "em", "" ) ) * eminpx;
+ }
+ }
+
+ if( !min && !max ||
+ ( !min || min && currWidth >= min ) &&
+ ( !max || max && currWidth <= max ) ){
if( !styleBlocks[ thisstyle.media ] ){
styleBlocks[ thisstyle.media ] = [];
}

0 comments on commit 2ad79c9

Please sign in to comment.