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 ===============================
// <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(' '),
classes = [],
docElement = document.documentElement,
@ -56,24 +93,24 @@ if ( !window.Modernizr ) {
{
name : 'csstransforms3d',
result : function() {
var ret = !!getStyleProperty('perspective');
console.log( ret )
if (ret){
var test = !!getStyleProperty('perspective');
// double check for Chrome's false positive
if ( test ){
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),(') +
'modernizr){#modernizr{height:3px}}';
document.getElementsByTagName('head')[0].appendChild(st);
st.textContent = mq + '{#modernizr{height:3px}}';
(doc.head || doc.getElementsByTagName('head')[0]).appendChild(st);
div.id = 'modernizr';
docElement.appendChild(div);
ret = div.offsetHeight === 3;
test = div.offsetHeight === 3;
st.parentNode.removeChild(st);
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.
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;
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 <html> element.
docElement.className += ' ' + classes.join( ' ' );
window.Modernizr = miniModernizr;
return miniModernizr;
}
})(this,this.document);
Loading…
Cancel
Save