Skip to content

Commit

Permalink
Made the function definition related to UA environment, matchMedia ch…
Browse files Browse the repository at this point in the history
…eck only happened once.
  • Loading branch information
swaydeng committed Sep 4, 2013
1 parent 26f64a2 commit ccb30ac
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/testMediaQuery.js
Expand Up @@ -2,21 +2,27 @@ define(['injectElementWithStyles'], function( injectElementWithStyles ) {
// adapted from matchMedia polyfill
// by Scott Jehl and Paul Irish
// gist.github.com/786768
var testMediaQuery = function( mq ) {
var testMediaQuery = (function () {
var matchMedia = window.matchMedia || window.msMatchMedia;
var bool;
if ( matchMedia ) {
return matchMedia(mq) && matchMedia(mq).matches || false;
return function ( mq ) {
var mql = matchMedia(mq);
return mql && mql.matches || false;
};
}

injectElementWithStyles('@media ' + mq + ' { #modernizr { position: absolute; } }', function( node ) {
bool = (window.getComputedStyle ?
getComputedStyle(node, null) :
node.currentStyle)['position'] == 'absolute';
});
return function ( mq ) {
var bool = false;

return bool;
};
injectElementWithStyles('@media ' + mq + ' { #modernizr { position: absolute; } }', function( node ) {
bool = (window.getComputedStyle ?
window.getComputedStyle(node, null) :
node.currentStyle)['position'] == 'absolute';
});

return bool;
};
})();

return testMediaQuery;
});

0 comments on commit ccb30ac

Please sign in to comment.