MooModernizr 1.1 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.1.
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
The inputattrubutes is an object Browser.Features.inputattrubutes.
So the types can be accessed by Browser.Features.inputattrubutes.autocomplete
: 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 navigator.onLine. This test will return false if the user agent will not contact the network when the user follows links or when a script requests a remote page (or knows that such an attempt would fail), and must return true otherwise.
Browser.Features.offlinedetection
Test if the browsers supports window.postMessage, is a method for safely enabling cross-origin communication.
Browser.Features.postmessage
Test if the browsers supports Database storage
Browser.Features.webdatabase
Test for the document.querySeletor
Browser.Features.query
Test for the native JSON api
Browser.Features.json
Browser.Features.inputtypes
Browser.Features.inputattributes
Deprecated: use $extend(Browser.Features,{fontface: function(){...}); instead.
Check for the test function here
I did not include this test because it would make the file to heavy, since I try to keep it as small as posible.
If you want, you can add more featues and test using the $extend method of MooTools.
$extend(Browser.Features,{
myTest: function(){
return 1.0 === 1;
}
});
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(Browser,{
enableHTML5: function(){
elems = 'abbr article aside audio canvas datalist details eventsource figure footer'
+' header hgroup mark menu meter nav output progress section time video';
elems.split(' ').each(function(tag){
new Element(tag);
})
mooModernizr.enableHTML5 = $lambda(true);
return true;
}
});
Browser.enableHTML5();