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. 90
      src/mini-modernizr.js

90
src/mini-modernizr.js

@ -45,63 +45,59 @@ 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 = [
return !!getStyleProperty('transform'); {
name : 'csstransforms',
result : function() {
return !!getStyleProperty('transform');
}
}, },
csstransforms3d : function() { {
var ret = !!getStyleProperty('perspective'); name : 'csstransforms3d',
result : function() {
if (ret){ var ret = !!getStyleProperty('perspective');
var st = document.createElement('style'), console.log( ret )
div = document.createElement('div'); if (ret){
var st = document.createElement('style'),
st.textContent = '@media ('+vendorCSSPrefixes.join('transform-3d),(') + div = document.createElement('div');
'modernizr){#modernizr{height:3px}}';
document.getElementsByTagName('head')[0].appendChild(st); st.textContent = '@media ('+vendorCSSPrefixes.join('transform-3d),(') +
div.id = 'modernizr'; 'modernizr){#modernizr{height:3px}}';
docElement.appendChild(div); document.getElementsByTagName('head')[0].appendChild(st);
div.id = 'modernizr';
ret = div.offsetHeight === 3; docElement.appendChild(div);
st.parentNode.removeChild(st); ret = div.offsetHeight === 3;
div.parentNode.removeChild(div);
st.parentNode.removeChild(st);
div.parentNode.removeChild(div);
}
return ret;
} }
return ret;
}, },
csstransitions : function() { {
return !!getStyleProperty('transitionProperty'); name : 'csstransitions',
result : function() {
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. classes.push( className );
var test = tests[ feature ]();
miniModernizr[ feature.toLowerCase() ] = test;
var className = ( test ? '' : 'no-' ) + feature.toLowerCase()
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