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

33
src/mini-modernizr.js

@ -41,7 +41,10 @@ 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){
var version = '1.6ish: miniModernizr for Molequul',
miniModernizr = {},
vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '), vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '),
classes = [], classes = [],
docElement = document.documentElement, docElement = document.documentElement,
@ -56,24 +59,24 @@ if ( !window.Modernizr ) {
{ {
name : 'csstransforms3d', name : 'csstransforms3d',
result : function() { result : function() {
var ret = !!getStyleProperty('perspective'); var test = !!getStyleProperty('perspective');
console.log( ret ) // double check for Chrome's false positive
if (ret){ if ( test ){
var st = document.createElement('style'), var st = document.createElement('style'),
div = document.createElement('div'); div = document.createElement('div'),
mq = '@media (' + vendorCSSPrefixes.join('transform-3d),(') + 'modernizr)';
st.textContent = '@media ('+vendorCSSPrefixes.join('transform-3d),(') + st.textContent = mq + '{#modernizr{height:3px}}';
'modernizr){#modernizr{height:3px}}'; (doc.head || doc.getElementsByTagName('head')[0]).appendChild(st);
document.getElementsByTagName('head')[0].appendChild(st);
div.id = 'modernizr'; div.id = 'modernizr';
docElement.appendChild(div); docElement.appendChild(div);
ret = div.offsetHeight === 3; test = div.offsetHeight === 3;
st.parentNode.removeChild(st); st.parentNode.removeChild(st);
div.parentNode.removeChild(div); div.parentNode.removeChild(div);
} }
return ret; return !!test;
} }
}, },
{ {
@ -88,16 +91,18 @@ if ( !window.Modernizr ) {
// 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;
var className = ( result ? '' : 'no-' ) + test.name;
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; return miniModernizr;
})(this,this.document);
} }
Loading…
Cancel
Save