Browse Source

miniModernizr : encapsulate in self-executing function; add some 1.6 touches

pull/14/head
David DeSandro 14 years ago
parent
commit
6afbf058b4
  1. 111
      src/mini-modernizr.js

111
src/mini-modernizr.js

@ -41,63 +41,68 @@ var getStyleProperty = (function(){
// <3<3<3 and thanks to Faruk and Paul for doing the heavy lifting // <3<3<3 and thanks to Faruk and Paul for doing the heavy lifting
if ( !window.Modernizr ) { if ( !window.Modernizr ) {
var miniModernizr = {}, window.Modernizr = (function(window,doc,undefined){
vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '),
classes = [], var version = '1.6ish: miniModernizr for Molequul',
docElement = document.documentElement, miniModernizr = {},
vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '),
tests = [ classes = [],
{ docElement = document.documentElement,
name : 'csstransforms',
result : function() { tests = [
return !!getStyleProperty('transform'); {
} name : 'csstransforms',
}, result : function() {
{ return !!getStyleProperty('transform');
name : 'csstransforms3d', }
result : function() { },
var ret = !!getStyleProperty('perspective'); {
console.log( ret ) name : 'csstransforms3d',
if (ret){ result : function() {
var st = document.createElement('style'), var test = !!getStyleProperty('perspective');
div = document.createElement('div'); // double check for Chrome's false positive
if ( test ){
st.textContent = '@media ('+vendorCSSPrefixes.join('transform-3d),(') + var st = document.createElement('style'),
'modernizr){#modernizr{height:3px}}'; div = document.createElement('div'),
document.getElementsByTagName('head')[0].appendChild(st); mq = '@media (' + vendorCSSPrefixes.join('transform-3d),(') + 'modernizr)';
div.id = 'modernizr';
docElement.appendChild(div); st.textContent = mq + '{#modernizr{height:3px}}';
(doc.head || doc.getElementsByTagName('head')[0]).appendChild(st);
ret = div.offsetHeight === 3; div.id = 'modernizr';
docElement.appendChild(div);
st.parentNode.removeChild(st);
div.parentNode.removeChild(div); test = div.offsetHeight === 3;
st.parentNode.removeChild(st);
div.parentNode.removeChild(div);
}
return !!test;
}
},
{
name : 'csstransitions',
result : function() {
return !!getStyleProperty('transitionProperty');
} }
return ret;
}
},
{
name : 'csstransitions',
result : function() {
return !!getStyleProperty('transitionProperty');
} }
} ]
] ;
;
// 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 i = 0, len = tests.length; i < len; i++ ) { for ( var i = 0, len = tests.length; i < len; i++ ) {
var test = tests[i]; var test = tests[i],
miniModernizr[ test.name ] = test.result(); result = test.result();
var className = ( test.result() ? '' : 'no-' ) + test.name; miniModernizr[ test.name ] = result;
classes.push( className ); var className = ( result ? '' : 'no-' ) + test.name;
} 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( ' ' );
return miniModernizr;
})(this,this.document);
window.Modernizr = miniModernizr;
} }
Loading…
Cancel
Save