Browse Source

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

For serious this time.
pull/14/head
David DeSandro 14 years ago
parent
commit
0a8283738d
  1. 71
      src/mini-modernizr.js

71
src/mini-modernizr.js

@ -39,9 +39,46 @@ var getStyleProperty = (function(){
// ========================= miniModernizr =============================== // ========================= miniModernizr ===============================
// <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 ) {
var miniModernizr = {}, /*!
* Modernizr v1.6ish: miniModernizr for Molequul
* http://www.modernizr.com
*
* Developed by:
* - Faruk Ates http://farukat.es/
* - Paul Irish http://paulirish.com/
*
* Copyright (c) 2009-2010
* Dual-licensed under the BSD or MIT licenses.
* http://www.modernizr.com/license/
*/
/*
* Modernizr is a script that detects native CSS3 and HTML5 features
* available in the current UA and provides an object containing all
* features with a true/false value, depending on whether the UA has
* native support for it or not.
*
* Modernizr will also add classes to the <html> element of the page,
* one for each feature it detects. If the UA supports it, a class
* like "cssgradients" will be added. If not, the class name will be
* "no-cssgradients". This allows for simple if-conditionals in your
* CSS, giving you fine control over the look & feel of your website.
*
* This version whittles down the script just to check support for
* CSS transitions, transforms, and 3D transforms.
*
* @author Faruk Ates
* @author Paul Irish
* @copyright (c) 2009-2010 Faruk Ates.
* @contributor Ben Alman
*/
window.Modernizr = 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 +93,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 +125,16 @@ 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