MooModernizr 1.0 tests the browser's CSS3 and HTML5 capabilities.
This by extending MooTools' Browser.Features object
with a variety of CSS3 and HTML5 features. It is a
MooTools 1.2 port
of Modernizr 1.0.
However some functionallity of Modernizr does not fit into the Browser.Features
object. But I will explain how you can add this functionallity yourself
whith some examples below.
The inputtypes is an object Browser.Features.inputtypes.
So the types can be accessed by Browser.Features.inputtypes.search
: Your Browser supports this feature
: To bad, your browser does not support this feature (yet)
You can use the new test just like Browser.Features.xpath and Browser.Features.xhr (link).
// Does the browser support textshadow
alert(Browser.Features.textshadow);
// Does the browser support cssclumns
alert(Browser.Features.csscolumns);
if(!Browser.Features.borderradius){
// Do something... (http://www.phatfusion.net/roundedcorners/)
var box = new RoundedCorners('.roundedContent', {radius: 49});
}
Most of the tests return true or false. But some tests
return a string. For example borderradius. As you can see
here, Firefox
uses another attribute for border-top-left-radius:
-moz-border-radius-topleft. To detect this, Browser.Features.borderradius
returns MozBorderRadiusTopright in Firefox. With this you can
create another if-else. The browser prefixes which are used are Moz, moz, webkit, o and ms.
Note: You also might be interested in the Modernizr docs
Browser.Features.canvas
Browser.Features.canvastext
Browser.Features.geolocation
Browser.Features.rgba
Browser.Features.hsla
Browser.Features.multiplebgs
Browser.Features.borderimage
Browser.Features.borderradius
Browser.Features.textshadow
Browser.Features.opacity
Browser.Features.cssanimations
Browser.Features.csscolumns
Browser.Features.cssgradients
Browser.Features.cssreflections
Browser.Features.csstransforms
Browser.Features.csstransforms3d
Browser.Features.csstransitions
Browser.Features.video
Browser.Features.audio
Test for the document.querySeletor
Browser.Features.query
Test for the native JSON api
Browser.Features.json
Browser.Features.inputtypes
Test for placeholder attribute of the input element
Browser.Features.inputplaceholder
Test for autofocus attribute of the input element
Browser.Features.inputautofocus
Test for @font-face
Browser.Features.fontface
This can be very handy. For example, you can put this in your css file.
body.boxshadow #contentbox {
box-shadow: 10px 10px 5px #888;
}
body.no-boxshadow #contentbox {
/* extra fat border, as alternative */
border: 10px black solid;
}
And this in your javascript file / document head
window.addEvent('domready',function(){
$each(Browser.Features, function(item,index){
if(item){
$(document.body).addClass(index);
}else{
$(document.body).addClass('no-'+index);
}
});
// Or if you only want to check for some features you can do this
['textshadow','borderradius'].each(function(item){
if(Browser.Features[item]){
$(document.body).addClass(item);
}else{
$(document.body).addClass('no-'+item);
}
});
});
Add this code before the domready event
$extend(mooModernizr,{
enableHTML5: function(){
elems = 'abbr article aside audio bb canvas datagrid datalist details dialog figure ';
elems += 'footer header mark menu meter nav output progress section time video';
elems.split(' ').each(function(tag){
new Element(tag);
})
mooModernizr.enableHTML5 = $lambda(true);
return true;
}
});
mooModernizr.enableHTML5();