Skip to content

Commit

Permalink
Fix for Firefox: verify that getComputedStyle is not returning null b…
Browse files Browse the repository at this point in the history
…efore using its result (it returns null if it's called inside a hidden iframe).
  • Loading branch information
felipebrahm committed Oct 10, 2014
1 parent 4eba958 commit a01e972
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 9 deletions.
6 changes: 5 additions & 1 deletion feature-detects/css/pseudoanimations.js
Expand Up @@ -8,6 +8,7 @@
define(['Modernizr', 'testStyles', 'test/css/animations'], function (Modernizr) {
Modernizr.addTest('csspseudoanimations', function () {
var result = false;
var style;

if (!Modernizr.cssanimations || !window.getComputedStyle) {
return result;
Expand All @@ -21,7 +22,10 @@ define(['Modernizr', 'testStyles', 'test/css/animations'], function (Modernizr)
].join('');

Modernizr.testStyles(styles, function (elem) {
result = window.getComputedStyle(elem, ':before').getPropertyValue('font-size') === '10px';
style = window.getComputedStyle(elem, ':before');
if(style !== null) {
result = style.getPropertyValue('font-size') === '10px';
}
});

return result;
Expand Down
9 changes: 6 additions & 3 deletions feature-detects/css/pseudotransitions.js
Expand Up @@ -8,6 +8,7 @@
define(['Modernizr', 'testStyles', 'test/css/transitions'], function (Modernizr) {
Modernizr.addTest('csspseudotransitions', function () {
var result = false;
var style;

if (!Modernizr.csstransitions || !window.getComputedStyle) {
return result;
Expand All @@ -19,9 +20,11 @@ define(['Modernizr', 'testStyles', 'test/css/transitions'], function (Modernizr)

Modernizr.testStyles(styles, function (elem) {
// Force rendering of the element's styles so that the transition will trigger
window.getComputedStyle(elem, ':before').getPropertyValue('font-size');
elem.className += 'trigger';
result = window.getComputedStyle(elem, ':before').getPropertyValue('font-size') === '5px';
style = window.getComputedStyle(elem, ':before');
if(style !== null) {
elem.className += 'trigger';
result = window.getComputedStyle(elem, ':before').getPropertyValue('font-size') === '5px';
}
});

return result;
Expand Down
13 changes: 10 additions & 3 deletions feature-detects/css/subpixelfont.js
Expand Up @@ -26,8 +26,15 @@ define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
function( elem ) {
var subpixel = elem.firstChild;
subpixel.innerHTML = 'This is a text written in Arial';
Modernizr.addTest('subpixelfont', window.getComputedStyle ?
window.getComputedStyle(subpixel, null).getPropertyValue('width') !== '44px'
: false);
Modernizr.addTest('subpixelfont', function() {
var style;
var result = false;

if(window.getComputedStyle && (style = window.getComputedStyle(subpixel, null)) !== null) {
result = style.getPropertyValue('width') !== '44px';
}

return result;
});
}, 1, ['subpixel']);
});
5 changes: 4 additions & 1 deletion feature-detects/elem/ruby.js
Expand Up @@ -42,9 +42,12 @@ define(['Modernizr', 'createElement', 'docElement'], function( Modernizr, create

function getStyle( element, styleProperty ) {
var result;
var style;

if ( window.getComputedStyle ) { // for non-IE browsers
result = document.defaultView.getComputedStyle(element,null).getPropertyValue(styleProperty);
if ( (style = document.defaultView.getComputedStyle(element,null)) !== null ) {
result = style.getPropertyValue(styleProperty);
}
} else if ( element.currentStyle ) { // for IE
result = element.currentStyle[styleProperty];
}
Expand Down
4 changes: 3 additions & 1 deletion feature-detects/inputtypes.js
Expand Up @@ -53,6 +53,7 @@ define(['Modernizr', 'inputElem', 'docElement', 'inputtypes', 'inputs', 'smile']
var inputElemType;
var defaultView;
var len = props.length;
var style;

for ( var i = 0; i < len; i++ ) {

Expand All @@ -74,7 +75,8 @@ define(['Modernizr', 'inputElem', 'docElement', 'inputtypes', 'inputs', 'smile']

// Safari 2-4 allows the smiley as a value, despite making a slider
bool = defaultView.getComputedStyle &&
defaultView.getComputedStyle(inputElem, null).WebkitAppearance !== 'textfield' &&
(style = defaultView.getComputedStyle(inputElem, null)) !== null &&
style.WebkitAppearance !== 'textfield' &&
// Mobile android web browser has false positive, so must
// check the height to see if the widget is actually there.
(inputElem.offsetHeight !== 0);
Expand Down

0 comments on commit a01e972

Please sign in to comment.