Permalink
Browse files

included the window.matchMedia polyfill externally from the main resp…

…ond.js function. The source code for this polyfill is here https://github.com/paulirish/matchMedia.js, and including it out-of-the-box will make things easier to keep updated, and allow for smaller file compression for those already including it via Modernizr or otherwise (if you are, you can delete it from Respond.js).
  • Loading branch information...
1 parent 8016973 commit 4d60f45716b8395e6f24238f9dc5e34c857e87f2 scottjehl committed Jan 16, 2012
Showing with 40 additions and 40 deletions.
  1. +5 −1 respond.min.js
  2. +35 −39 respond.src.js
View

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

Oops, something went wrong.
View
@@ -1,16 +1,47 @@
+/*! matchMedia() polyfill - Test a CSS media type/query in JS. Authors & copyright (c) 2012: Scott Jehl, Paul Irish, Nicholas Zakas. Dual MIT/BSD license */
+/*! NOTE: If you're already including a window.matchMedia polyfill via Modernizr or otherwise, you don't need this part */
+window.matchMedia = window.matchMedia || (function(doc, undefined){
+
+ var bool,
+ docElem = doc.documentElement,
+ refNode = docElem.firstElementChild || docElem.firstChild,
+ // fakeBody required for <FF4 when executed in <head>
+ fakeBody = doc.createElement('body'),
+ div = doc.createElement('div');
+
+ div.id = 'mq-test-1';
+ div.style.cssText = "position:absolute;top:-100em";
+ fakeBody.appendChild(div);
+
+ return function(q){
+
+ div.innerHTML = '&shy;<style media="'+q+'"> #mq-test-1 { width: 42px; }</style>';
+
+ docElem.insertBefore(fakeBody, refNode);
+ bool = div.offsetWidth == 42;
+ docElem.removeChild(fakeBody);
+
+ return { matches: bool, media: q };
+ };
+
+})(document);
+
+
+
+
/*! Respond.js v1.0.1pre: min/max-width media query polyfill. (c) Scott Jehl. MIT/GPLv2 Lic. j.mp/respondjs */
-(function( win, mqSupported ){
+(function( win ){
//exposed namespace
win.respond = {};
//define update even in native-mq-supporting browsers, to avoid errors
respond.update = function(){};
//expose media query support flag for external use
- respond.mediaQueriesSupported = mqSupported;
+ respond.mediaQueriesSupported = win.matchMedia && win.matchMedia( "only all" ).matches;
//if media queries are supported, exit here
- if( mqSupported ){ return; }
+ if( respond.mediaQueriesSupported ){ return; }
//define vars
var doc = win.document,
@@ -243,39 +274,4 @@
else if( win.attachEvent ){
win.attachEvent( "onresize", callMedia );
}
-})(
- this,
- (function( win ){
-
- //for speed, flag browsers with window.matchMedia support and IE 9 as supported
- if( win.matchMedia ){ return true; }
-
- var bool,
- doc = document,
- docElem = doc.documentElement,
- refNode = docElem.firstElementChild || docElem.firstChild,
- // fakeBody required for <FF4 when executed in <head>
- fakeUsed = !doc.body,
- fakeBody = doc.body || doc.createElement( "body" ),
- div = doc.createElement( "div" ),
- q = "only all";
-
- div.id = "mq-test-1";
- div.style.cssText = "position:absolute;top:-99em";
- fakeBody.appendChild( div );
-
- div.innerHTML = '_<style media="'+q+'"> #mq-test-1 { width: 9px; }</style>';
- if( fakeUsed ){
- docElem.insertBefore( fakeBody, refNode );
- }
- div.removeChild( div.firstChild );
- bool = div.offsetWidth == 9;
- if( fakeUsed ){
- docElem.removeChild( fakeBody );
- }
- else{
- fakeBody.removeChild( div );
- }
- return bool;
- })( this )
-);
+})(this);

0 comments on commit 4d60f45

Please sign in to comment.