Skip to content

Commit

Permalink
more docs around modernizr.mq(). fixes Modernizr#232
Browse files Browse the repository at this point in the history
  • Loading branch information
paulirish committed May 22, 2011
1 parent 4f010ed commit 9b85d2d
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 10 deletions.
21 changes: 12 additions & 9 deletions modernizr.js
Expand Up @@ -881,27 +881,26 @@ window.Modernizr = (function( window, document, undefined ) {
* @param test - Function returning true if feature is supported, false if not
*/
Modernizr.addTest = function ( feature, test ) {
if ( typeof feature === "object" ) {
if ( typeof feature == "object" ) {
for ( var key in feature ) {
if ( hasOwnProperty( feature, key ) ) {
Modernizr.addTest( key, feature[ key ] );
}
}
} else {
// assume strings

feature = feature.toLowerCase();

if ( Modernizr[feature] ) {
if ( Modernizr[feature] !== undefined ) {
// we're going to quit if you're trying to overwrite an existing test
// if we were to allow it, we'd do this:
// var re = new RegExp("\\b(no-)?" + feature + "\\b"); // f'n strings need \\
// var re = new RegExp("\\b(no-)?" + feature + "\\b");
// docElement.className = docElement.className.replace( re, '' );
// but, no rly, stuff 'em.
return;
}

test = typeof test === "boolean" ? test : !!test();
test = typeof test == "boolean" ? test : !!test();

docElement.className += ' ' + (test ? '' : 'no-') + feature;
Modernizr[feature] = test;
Expand All @@ -912,9 +911,7 @@ window.Modernizr = (function( window, document, undefined ) {
};


/**
* Reset m.style.cssText to nothing to reduce memory footprint.
*/
// Reset modElem.cssText to nothing to reduce memory footprint.
setCss('');
modElem = inputElem = null;

Expand Down Expand Up @@ -1050,8 +1047,14 @@ window.Modernizr = (function( window, document, undefined ) {
Modernizr._prefixes = prefixes;
Modernizr._domPrefixes = domPrefixes;


// Modernizr.mq tests a given media query, live against the current state of the window
// A few important distinctions:
// * If a browser does not support media queries at all (eg. oldIE) the mq() will always return false
// * A max-width or orientation query will be evaluated against the current state, which may change later.

Modernizr.mq = testMediaQuery; // Modernizr.mq('only screen and (max-width:768)')


Modernizr.event = isEventSupported; // Modernizr.hasEvent('gesturestart')
Modernizr.testAllProps = testPropsAll; // Modernizr.testAllProps('box-sizing')
Modernizr.testProp = testProps; // Modernizr.testProp('pointer-events')
Expand Down
5 changes: 4 additions & 1 deletion test/unit.js
Expand Up @@ -188,7 +188,7 @@ test('Modernizr properties are looking good',function(){



test('Modernizr.addTest()',21,function(){
test('Modernizr.addTest()',22,function(){

var docEl = document.documentElement;

Expand Down Expand Up @@ -270,6 +270,9 @@ test('Modernizr.addTest()',21,function(){
equals(Modernizr.testobjfntrue, true, 'Modernizr.addTest({feature: bool}): positive prop added');


Modernizr.addTest('chainone', true).addTest({ chaintwo: true }).addTest('chainthree', function(){ return true; });
ok( Modernizr.chainone == Modernizr.chaintwo == Modernizr.chainthree, 'addTest is chainable');


}); // eo addTest

Expand Down

0 comments on commit 9b85d2d

Please sign in to comment.