From 6afbf058b4565e9f985c2b74ab1b6b15e4403c50 Mon Sep 17 00:00:00 2001 From: David DeSandro Date: Mon, 25 Oct 2010 21:57:59 -0400 Subject: [PATCH] miniModernizr : encapsulate in self-executing function; add some 1.6 touches --- src/mini-modernizr.js | 111 ++++++++++++++++++++++-------------------- 1 file changed, 58 insertions(+), 53 deletions(-) diff --git a/src/mini-modernizr.js b/src/mini-modernizr.js index 326f4ea..762e4fa 100644 --- a/src/mini-modernizr.js +++ b/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 if ( !window.Modernizr ) { - var miniModernizr = {}, - vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '), - classes = [], - docElement = document.documentElement, - - tests = [ - { - name : 'csstransforms', - result : function() { - return !!getStyleProperty('transform'); - } - }, - { - name : 'csstransforms3d', - result : function() { - var ret = !!getStyleProperty('perspective'); - console.log( ret ) - if (ret){ - var st = document.createElement('style'), - div = document.createElement('div'); - - st.textContent = '@media ('+vendorCSSPrefixes.join('transform-3d),(') + - 'modernizr){#modernizr{height:3px}}'; - document.getElementsByTagName('head')[0].appendChild(st); - div.id = 'modernizr'; - docElement.appendChild(div); - - ret = div.offsetHeight === 3; - - st.parentNode.removeChild(st); - div.parentNode.removeChild(div); + window.Modernizr = (function(window,doc,undefined){ + + var version = '1.6ish: miniModernizr for Molequul', + miniModernizr = {}, + vendorCSSPrefixes = ' -o- -moz- -ms- -webkit- -khtml- '.split(' '), + classes = [], + docElement = document.documentElement, + + tests = [ + { + name : 'csstransforms', + result : function() { + return !!getStyleProperty('transform'); + } + }, + { + name : 'csstransforms3d', + result : function() { + var test = !!getStyleProperty('perspective'); + // double check for Chrome's false positive + if ( test ){ + var st = document.createElement('style'), + div = document.createElement('div'), + mq = '@media (' + vendorCSSPrefixes.join('transform-3d),(') + 'modernizr)'; + + st.textContent = mq + '{#modernizr{height:3px}}'; + (doc.head || doc.getElementsByTagName('head')[0]).appendChild(st); + div.id = 'modernizr'; + docElement.appendChild(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. - for ( var i = 0, len = tests.length; i < len; i++ ) { - var test = tests[i]; - miniModernizr[ test.name ] = test.result(); - var className = ( test.result() ? '' : 'no-' ) + test.name; - classes.push( className ); - } + // Run through all tests and detect their support in the current UA. + for ( var i = 0, len = tests.length; i < len; i++ ) { + var test = tests[i], + result = test.result(); + miniModernizr[ test.name ] = result; + var className = ( result ? '' : 'no-' ) + test.name; + classes.push( className ); + } - // Add the new classes to the element. - docElement.className += ' ' + classes.join( ' ' ); + // Add the new classes to the element. + docElement.className += ' ' + classes.join( ' ' ); + + return miniModernizr; + + })(this,this.document); - window.Modernizr = miniModernizr; - - } \ No newline at end of file