Skip to content

Commit

Permalink
Removing the testBundle method fixes #585
Browse files Browse the repository at this point in the history
 - Affects fontface, touch, csstransforms3d and generatedcontent tests
 - Changed csstransforms3d to only inject an element an media query if needed and only have webkit and non prefixed values, see line 646.
 - Touch test only injects and element if first statement fails, see line 439.
  • Loading branch information
ryanseddon committed May 21, 2012
1 parent 4c5d38a commit 4807a83
Showing 1 changed file with 32 additions and 53 deletions.
85 changes: 32 additions & 53 deletions modernizr.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,54 +377,6 @@ window.Modernizr = (function( window, document, undefined ) {
}
/*>>testallprops*/

/*>>testBundle*/
/**
* testBundle tests a list of CSS features that require element and style injection.
* By bundling them together we can reduce the need to touch the DOM multiple times.
*/
var testBundle = (function( styles, tests ) {
var style = styles.join(''),
len = tests.length;

injectElementWithStyles(style, function( node, rule ) {
var style = document.styleSheets[document.styleSheets.length - 1],
// IE8 will bork if you create a custom build that excludes both fontface and generatedcontent tests.
// So we check for cssRules and that there is a rule available
// More here: github.com/Modernizr/Modernizr/issues/288 & github.com/Modernizr/Modernizr/issues/293
cssText = style ? (style.cssRules && style.cssRules[0] ? style.cssRules[0].cssText : style.cssText || '') : '',
children = node.childNodes, hash = {};

while ( len-- ) {
hash[children[len].id] = children[len];
}

/*>>touch*/ Modernizr['touch'] = ('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch || (hash['touch'] && hash['touch'].offsetTop) === 9; /*>>touch*/
/*>>csstransforms3d*/ Modernizr['csstransforms3d'] = (hash['csstransforms3d'] && hash['csstransforms3d'].offsetLeft) === 9 && hash['csstransforms3d'].offsetHeight === 3; /*>>csstransforms3d*/
/*>>generatedcontent*/Modernizr['generatedcontent'] = (hash['generatedcontent'] && hash['generatedcontent'].offsetHeight) >= 1; /*>>generatedcontent*/
/*>>fontface*/ Modernizr['fontface'] = /src/i.test(cssText) &&
cssText.indexOf(rule.split(' ')[0]) === 0; /*>>fontface*/
}, len, tests);

})([
// Pass in styles to be injected into document
/*>>fontface*/ '@font-face {font-family:"font";src:url("https://")}' /*>>fontface*/

/*>>touch*/ ,['@media (',prefixes.join('touch-enabled),('),mod,')',
'{#touch{top:9px;position:absolute}}'].join('') /*>>touch*/

/*>>csstransforms3d*/ ,['@media (',prefixes.join('transform-3d),('),mod,')',
'{#csstransforms3d{left:9px;position:absolute;height:3px;}}'].join('')/*>>csstransforms3d*/

/*>>generatedcontent*/,['#generatedcontent:after{content:"',smile,'";visibility:hidden}'].join('') /*>>generatedcontent*/
],
[
/*>>fontface*/ 'fontface' /*>>fontface*/
/*>>touch*/ ,'touch' /*>>touch*/
/*>>csstransforms3d*/ ,'csstransforms3d' /*>>csstransforms3d*/
/*>>generatedcontent*/,'generatedcontent' /*>>generatedcontent*/

]);/*>>testBundle*/


/**
* Tests
Expand Down Expand Up @@ -482,7 +434,17 @@ window.Modernizr = (function( window, document, undefined ) {
*/

tests['touch'] = function() {
return Modernizr['touch'];
var bool;

if(('ontouchstart' in window) || window.DocumentTouch && document instanceof DocumentTouch) {
bool = true;
} else {
injectElementWithStyles(['@media (',prefixes.join('touch-enabled),('),mod,')','{#modernizr{top:9px;position:absolute}}'].join(''), function( node ) {
bool = node.offsetTop === 9;
});
}

return bool;
};


Expand Down Expand Up @@ -684,8 +646,10 @@ window.Modernizr = (function( window, document, undefined ) {
if ( ret && 'webkitPerspective' in docElement.style ) {

// Webkit allows this media query to succeed only if the feature is enabled.
// `@media (transform-3d),(-o-transform-3d),(-moz-transform-3d),(-ms-transform-3d),(-webkit-transform-3d),(modernizr){ ... }`
ret = Modernizr['csstransforms3d'];
// `@media (transform-3d),(-webkit-transform-3d){ ... }`
injectElementWithStyles('@media (transform-3d),(-webkit-transform-3d){#modernizr{left:9px;position:absolute;height:3px;}}', function( node, rule ) {

This comment has been minimized.

Copy link
@keeyipchan

keeyipchan Sep 26, 2012

This somehow disables native kinetic scrolling on iOS 6; scrolling still works but is not animated.
The scrollbar that usually appears is also not visible.

This comment has been minimized.

Copy link
@ryanseddon

ryanseddon Sep 26, 2012

Author Member

@keeyipchan can you file an issue with a test case please.

This comment has been minimized.

Copy link
@keeyipchan

keeyipchan Sep 26, 2012

Issue: #707

I made a standalone test and do not see this bug, it must be a combination of things. I will need to narrow down the specific conditions from my webapp.

ret = node.offsetLeft === 9 && node.offsetHeight === 3;
});
}
return ret;
};
Expand All @@ -704,13 +668,28 @@ window.Modernizr = (function( window, document, undefined ) {
// WebOS github.com/Modernizr/Modernizr/issues/342
// WP7 github.com/Modernizr/Modernizr/issues/538
tests['fontface'] = function() {
return Modernizr['fontface'];
var bool;

injectElementWithStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) {
var style = document.styleSheets[document.styleSheets.length - 1],
cssText = style ? (style.cssRules && style.cssRules[0] ? style.cssRules[0].cssText : style.cssText || '') : '';

bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0;
});

return bool;
};
/*>>fontface*/

// CSS generated content detection
tests['generatedcontent'] = function() {
return Modernizr['generatedcontent'];
var bool;

injectElementWithStyles(['#modernizr:after{content:"',smile,'";visibility:hidden}'].join(''), function( node ) {
bool = node.offsetHeight >= 1;
});

return bool;
};


Expand Down

0 comments on commit 4807a83

Please sign in to comment.