fontface.js 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. /*!
  2. {
  3. "name": "@font-face",
  4. "property": "fontface",
  5. "authors": ["Diego Perini", "Mat Marquis"],
  6. "tags": ["css"],
  7. "knownBugs": [
  8. "False Positive: WebOS https://github.com/Modernizr/Modernizr/issues/342",
  9. "False Positive: WP7 https://github.com/Modernizr/Modernizr/issues/538"
  10. ],
  11. "notes": [{
  12. "name": "@font-face detection routine by Diego Perini",
  13. "href": "http://javascript.nwbox.com/CSSSupport/"
  14. },{
  15. "name": "Filament Group @font-face compatibility research",
  16. "href": "https://docs.google.com/presentation/d/1n4NyG4uPRjAA8zn_pSQ_Ket0RhcWC6QlZ6LMjKeECo0/edit#slide=id.p"
  17. },{
  18. "name": "Filament Grunticon/@font-face device testing results",
  19. "href": "https://docs.google.com/spreadsheet/ccc?key=0Ag5_yGvxpINRdHFYeUJPNnZMWUZKR2ItMEpRTXZPdUE#gid=0"
  20. },{
  21. "name": "CSS fonts on Android",
  22. "href": "https://stackoverflow.com/questions/3200069/css-fonts-on-android"
  23. },{
  24. "name": "@font-face and Android",
  25. "href": "http://archivist.incutio.com/viewlist/css-discuss/115960"
  26. }]
  27. }
  28. !*/
  29. define(['Modernizr', 'testStyles'], function(Modernizr, testStyles) {
  30. var blacklist = (function() {
  31. var ua = navigator.userAgent;
  32. var webos = ua.match(/w(eb)?osbrowser/gi);
  33. var wppre8 = ua.match(/windows phone/gi) && ua.match(/iemobile\/([0-9])+/gi) && parseFloat(RegExp.$1) >= 9;
  34. return webos || wppre8;
  35. }());
  36. if (blacklist) {
  37. Modernizr.addTest('fontface', false);
  38. } else {
  39. testStyles('@font-face {font-family:"font";src:url("https://")}', function(node, rule) {
  40. var style = document.getElementById('smodernizr');
  41. var sheet = style.sheet || style.styleSheet;
  42. var cssText = sheet ? (sheet.cssRules && sheet.cssRules[0] ? sheet.cssRules[0].cssText : sheet.cssText || '') : '';
  43. var bool = /src/i.test(cssText) && cssText.indexOf(rule.split(' ')[0]) === 0;
  44. Modernizr.addTest('fontface', bool);
  45. });
  46. }
  47. });