Skip to content

Commit

Permalink
csstransform3d detect should prefer css conditionals - fixes Moderniz…
Browse files Browse the repository at this point in the history
…r#1512

Use Modernizr detect for supports in transforms3d
  • Loading branch information
jacobrossi committed Feb 5, 2015
1 parent 8aa80ae commit a54308e
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions feature-detects/css/transforms3d.js
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
] ]
} }
!*/ !*/
define(['Modernizr', 'testAllProps', 'testStyles', 'docElement'], function( Modernizr, testAllProps, testStyles, docElement ) { define(['Modernizr', 'testAllProps', 'testStyles', 'docElement', 'test/css/supports'], function( Modernizr, testAllProps, testStyles, docElement ) {
Modernizr.addTest('csstransforms3d', function() { Modernizr.addTest('csstransforms3d', function() {
var ret = !!testAllProps('perspective', '1px', true); var ret = !!testAllProps('perspective', '1px', true);
var usePrefix = Modernizr._config.usePrefixes; var usePrefix = Modernizr._config.usePrefixes;
Expand All @@ -19,12 +19,17 @@ define(['Modernizr', 'testAllProps', 'testStyles', 'docElement'], function( Mode
// some conditions. As a result, Webkit typically recognizes the syntax but // some conditions. As a result, Webkit typically recognizes the syntax but
// will sometimes throw a false positive, thus we must do a more thorough check: // will sometimes throw a false positive, thus we must do a more thorough check:
if ( ret && (!usePrefix || 'webkitPerspective' in docElement.style )) { if ( ret && (!usePrefix || 'webkitPerspective' in docElement.style )) {

var mq;
// Webkit allows this media query to succeed only if the feature is enabled. // Use CSS Conditional Rules if available
// `@media (transform-3d),(-webkit-transform-3d){ ... }` if (Modernizr.supports) {
mq = '@supports (perspective: 1px)';
} else {
// Otherwise, Webkit allows this media query to succeed only if the feature is enabled.
// `@media (transform-3d),(-webkit-transform-3d){ ... }`
mq = '@media (transform-3d)';
if (usePrefix ) mq += ',(-webkit-transform-3d)';
}
// If loaded inside the body tag and the test element inherits any padding, margin or borders it will fail #740 // If loaded inside the body tag and the test element inherits any padding, margin or borders it will fail #740
var mq = '@media (transform-3d)';
if (usePrefix ) mq += ',(-webkit-transform-3d)';
mq += '{#modernizr{left:9px;position:absolute;height:5px;margin:0;padding:0;border:0}}'; mq += '{#modernizr{left:9px;position:absolute;height:5px;margin:0;padding:0;border:0}}';


testStyles(mq, function( elem ) { testStyles(mq, function( elem ) {
Expand Down

0 comments on commit a54308e

Please sign in to comment.