Skip to content

Commit

Permalink
Fix #775: Fix has-css3 feature detection, especially css-transforms3d
Browse files Browse the repository at this point in the history
css-transforms3d was testing using a media query which is not supported by
non-webkit browsers.  Testing using the `perspective` style property is
sufficient in all but now-ancient versions of Chrome.
  • Loading branch information
Kenneth G. Franqueiro committed Mar 24, 2014
1 parent 745a5be commit 660eb0f
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 58 deletions.
16 changes: 0 additions & 16 deletions css/has-transforms3d.css

This file was deleted.

64 changes: 22 additions & 42 deletions util/has-css3.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
define(["dojo/has", "xstyle/css!../css/has-transforms3d.css"],
define(["dojo/has"],
function(has){
// This module defines feature tests for CSS3 features such as transitions.
// The css-transitions, css-transforms, and css-transforms3d has-features
Expand All @@ -9,20 +9,36 @@ function(has){

var cssPrefixes = ["ms", "O", "Moz", "Webkit"];

has.add("css-transitions", function(global, doc, element){
function testStyle(element, property) {
var style = element.style,
i;

if(style.transitionProperty !== undefined){ // standard, no vendor prefix
if (property in style) {
// Standard, no prefix
return true;
}
property = property.slice(0, 1).toUpperCase() + property.slice(1);
for (i = cssPrefixes.length; i--;) {
if (style[cssPrefixes[i] + "TransitionProperty"] !== undefined) {
return cssPrefixes[i]; // vendor-specific css property prefix
if ((cssPrefixes[i] + property) in style) {
// Vendor-specific css property prefix
return cssPrefixes[i];
}
}

return false; // otherwise, not supported
// Otherwise, not supported
return false;
}

has.add("css-transitions", function(global, doc, element){
return testStyle(element, "transitionProperty");
});

has.add("css-transforms", function(global, doc, element){
return testStyle(element, "transform");
});

has.add("css-transforms3d", function(global, doc, element){
return testStyle(element, "perspective");
});

has.add("transitionend", function(){
Expand All @@ -38,41 +54,5 @@ function(has){
}[tpfx];
});

has.add("css-transforms", function(global, doc, element){
var style = element.style, i;
if (style.transformProperty !== undefined) {
return true; // standard, no vendor prefix
}
for (i = cssPrefixes.length; i--;) {
if (style[cssPrefixes[i] + "Transform"] !== undefined) {
return cssPrefixes[i];
}
}

return false; // otherwise, not supported
});

has.add("css-transforms3d", function(global, doc, element){
var left,
result = false;

// Apply csstransforms3d class to test transform-3d media queries.
element.className = "has-csstransforms3d";
// Add to body to allow measurement.
document.body.appendChild(element);
left = element.offsetLeft;

if (left === 9) {
result = true; // standard, no prefix
} else if (left > 9){
// Matched one of the vendor prefixes; offset indicates which.
result = cssPrefixes[left - 10] || false;
}
document.body.removeChild(element);
element.className = "";

return result;
});

return has;
});

0 comments on commit 660eb0f

Please sign in to comment.