Skip to content

Commit

Permalink
cleanup testMediaQuery, remove caching.
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed Apr 12, 2011
1 parent 9582d87 commit d343ec3
Showing 1 changed file with 16 additions and 20 deletions.
36 changes: 16 additions & 20 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -136,27 +136,23 @@ window.Modernizr = (function(window,document,undefined){
// by Scott Jehl and Paul Irish
// gist.github.com/786768

// todo: consider using http://javascript.nwbox.com/CSSSupport/css-support.js instead
testMediaQuery = (function(mq){
testMediaQuery = function(mq){

var cache = {};

return function(mq){
if (cache[mq] == undefined) {
if (window.matchMedia){
return (cache[mq] = matchMedia(mq).matches);
}

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

})(),
if (window.matchMedia){
return matchMedia(mq).matches;
}

var bool;

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

return bool;

},


/**
Expand Down

0 comments on commit d343ec3

Please sign in to comment.