Initial version of nativeCSSDetect() - only accepts a string e.g. '(flex-wrap:reverse)'; would quite like to overload the interface

This commit is contained in:
Stu Cox
2013-02-19 21:47:24 +00:00
parent 2a6a5483c5
commit 70ba7de432

25
src/nativeCSSDetect.js Normal file
View File

@@ -0,0 +1,25 @@
define(['injectElementWithStyles'], function ( injectElementWithStyles ) {
// Function to allow us to use native feature detection functionality if available.
// Only accepts the string notation, i.e.: `nativeCSSDetect('(display:flex)')`, not
// `nativeCSSDetect('display', 'flex')`
function nativeCSSDetect ( str ) {
// Start with the W3C version: http://www.w3.org/TR/css3-conditional/#the-css-interface
if ('CSS' in window && 'supports' in window.CSS) {
return window.CSS.supports(str);
}
// Otherwise fall back to the at-rule for Opera: they made a bit of a hash of
// `window.CSS.supports()`, by implementing it as `window.supportsCSS()` which
// only supported f(property, value) calls rather than f(conditionText)
else if ('CSSSupportsRule' in window) {
return injectElementWithStyles('@supports ' + str + ' { #modernizr { position: absolute; } }', function( node ) {
return (window.getComputedStyle ?
getComputedStyle(node, null) :
node.currentStyle)['position'] == 'absolute';
});
}
else {
return undefined;
}
}
return nativeCSSDetect;
});