Skip to content

Commit

Permalink
Adds UA blacklist to @font-face test as a stopgap.
Browse files Browse the repository at this point in the history
This addresses the issue of false positives on WebOS, Android 2.0/2.1,
and Windows Phone 7-7.8 while we consider a more robust feature test.
Ref. #1120.
  • Loading branch information
Wilto committed Dec 6, 2013
1 parent ff40a84 commit 949d770
Showing 1 changed file with 32 additions and 9 deletions.
41 changes: 32 additions & 9 deletions feature-detects/css/fontface.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
{
"name": "@font-face",
"property": "fontface",
"authors": ["Diego Perini"],
"authors": ["Diego Perini", "Mat Marquis"],
"tags": ["css"],
"knownBugs": [
"False Positive: WebOS http://github.com/Modernizr/Modernizr/issues/342",
Expand All @@ -11,16 +11,39 @@
"notes": [{
"name": "@font-face detection routine by Diego Perini",
"href": "http://javascript.nwbox.com/CSSSupport/"
},{
"name": "Filament Group @font-face compatibility research",
"href": "https://docs.google.com/presentation/d/1n4NyG4uPRjAA8zn_pSQ_Ket0RhcWC6QlZ6LMjKeECo0/edit#slide=id.p"
},{
"name": "Filament Grunticon/@font-face device testing results",
"href": "https://docs.google.com/spreadsheet/ccc?key=0Ag5_yGvxpINRdHFYeUJPNnZMWUZKR2ItMEpRTXZPdUE#gid=0"
},{
"name": "CSS fonts on Android",
"href": "http://stackoverflow.com/questions/3200069/css-fonts-on-android"
},{
"name": "@font-face and Android",
"href": "http://archivist.incutio.com/viewlist/css-discuss/115960"
}]
}
!*/
define(['Modernizr', 'testStyles'], function( Modernizr, testStyles ) {
testStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) {
var style = document.getElementById('smodernizr');
var sheet = style.sheet || style.styleSheet;
var cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : '';
var bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0;

Modernizr.addTest('fontface', bool);
});
var blacklist = (function() {
var ua = navigator.userAgent;
var wkvers = ua.match( /applewebkit\/([0-9]+)/gi ) && parseFloat( RegExp.$1 );
var webos = ua.match( /w(eb)?osbrowser/gi );
var wppre8 = ua.match( /windows phone/gi ) && ua.match( /iemobile\/([0-9])+/gi ) && parseFloat( RegExp.$1 ) >= 9;
var oldandroid = wkvers < 533 && ua.match( /android/gi );
return webos || oldandroid || wppre8;
}());
if( blacklist ) {
Modernizr.addTest('fontface', false);
} else {
testStyles('@font-face {font-family:"font";src:url("https://")}', function( node, rule ) {
var style = document.getElementById('smodernizr');
var sheet = style.sheet || style.styleSheet;
var cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : '';
var bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0;
Modernizr.addTest('fontface', bool);
});
}
});

2 comments on commit 949d770

@timohanninen
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When will this be included to the production version? Sorry that I'm bothering you guys and asking, but I am absolute worthless in reading Github.

@patrickkettner
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hey @timohanninen, once we ship v 3, this will be included. You could always clone the repo and build it yourself though.

Please sign in to comment.