unicode.js 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. /*!
  2. {
  3. "name": "Unicode characters",
  4. "property": "unicode",
  5. "tags": ["encoding"],
  6. "warnings": [
  7. "positive Unicode support doesn't mean you can use it inside <title>, this seems more related to OS & Language packs"
  8. ]
  9. }
  10. !*/
  11. /* DOC
  12. Detects if unicode characters are supported in the current document.
  13. */
  14. define(['Modernizr', 'createElement', 'testStyles', 'isSVG'], function(Modernizr, createElement, testStyles, isSVG) {
  15. /**
  16. * Unicode special character support
  17. *
  18. * Detection is made by testing missing glyph box rendering against star character
  19. * If widths are the same, this "probably" means the browser didn't support the star character and rendered a glyph box instead
  20. * Just need to ensure the font characters have different widths
  21. */
  22. Modernizr.addTest('unicode', function() {
  23. var bool;
  24. var missingGlyph = createElement('span');
  25. var star = createElement('span');
  26. testStyles('#modernizr{font-family:Arial,sans;font-size:300em;}', function(node) {
  27. missingGlyph.innerHTML = isSVG ? '\u5987' : '&#5987;';
  28. star.innerHTML = isSVG ? '\u2606' : '&#9734;';
  29. node.appendChild(missingGlyph);
  30. node.appendChild(star);
  31. bool = 'offsetWidth' in missingGlyph && missingGlyph.offsetWidth !== star.offsetWidth;
  32. });
  33. return bool;
  34. });
  35. });