Browse Source

MiniModernizr : use array instead of object literal. It's only 3 tests

pull/14/head
David DeSandro 15 years ago
parent
commit
81cceeea06
  1. 50
      src/mini-modernizr.js

50
src/mini-modernizr.js

@ -45,13 +45,19 @@ if ( !window.Modernizr ) {
vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '), vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '),
classes = [], classes = [],
docElement = document.documentElement, docElement = document.documentElement,
tests = {
csstransforms : function() { tests = [
{
name : 'csstransforms',
result : function() {
return !!getStyleProperty('transform'); return !!getStyleProperty('transform');
}
}, },
csstransforms3d : function() { {
name : 'csstransforms3d',
result : function() {
var ret = !!getStyleProperty('perspective'); var ret = !!getStyleProperty('perspective');
console.log( ret )
if (ret){ if (ret){
var st = document.createElement('style'), var st = document.createElement('style'),
div = document.createElement('div'); div = document.createElement('div');
@ -68,40 +74,30 @@ if ( !window.Modernizr ) {
div.parentNode.removeChild(div); div.parentNode.removeChild(div);
} }
return ret; return ret;
}
}, },
csstransitions : function() { {
name : 'csstransitions',
result : function() {
return !!getStyleProperty('transitionProperty'); return !!getStyleProperty('transitionProperty');
} }
};
// hasOwnProperty shim by kangax needed for Safari 2.0 support
var _hasOwnProperty = ({}).hasOwnProperty, hasOwnProperty;
if (typeof _hasOwnProperty !== 'undefined' && typeof _hasOwnProperty.call !== 'undefined') {
hasOwnProperty = function (object, property) {
return _hasOwnProperty.call(object, property);
};
}
else {
hasOwnProperty = function (object, property) { /* yes, this can give false positives/negatives, but most of the time we don't care about those */
return ((property in object) && typeof object.constructor.prototype[property] === 'undefined');
};
} }
]
;
// Run through all tests and detect their support in the current UA. // Run through all tests and detect their support in the current UA.
for ( var feature in tests ) { for ( var i = 0, len = tests.length; i < len; i++ ) {
if ( hasOwnProperty( tests, feature ) ) { var test = tests[i];
// run the test, throw the return value into the Modernizr, miniModernizr[ test.name ] = test.result();
// then based on that boolean, define an appropriate className var className = ( test.result() ? '' : 'no-' ) + test.name;
// and push it into an array of classes we'll join later.
var test = tests[ feature ]();
miniModernizr[ feature.toLowerCase() ] = test;
var className = ( test ? '' : 'no-' ) + feature.toLowerCase()
classes.push( className ); classes.push( className );
} }
}
// Add the new classes to the <html> element. // Add the new classes to the <html> element.
docElement.className += ' ' + classes.join( ' ' ); docElement.className += ' ' + classes.join( ' ' );
window.Modernizr = miniModernizr; window.Modernizr = miniModernizr;
} }
Loading…
Cancel
Save