Skip to content

Instantly share code, notes, and snippets.

@scottjehl
Created April 17, 2013 19:04
Show Gist options
  • Save scottjehl/5406853 to your computer and use it in GitHub Desktop.
Save scottjehl/5406853 to your computer and use it in GitHub Desktop.

Revisions

  1. scottjehl renamed this gist Apr 17, 2013. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  2. scottjehl created this gist Apr 17, 2013.
    33 changes: 33 additions & 0 deletions gistfile1.txt
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,33 @@
    ...
    // test for font-face version to load via Data URI'd CSS
    // Basically, load WOFF unless it's android's default browser, which needs TTF, or ie8-, which needs eot
    var fonts = ns.files.css.fontsWOFF,
    ua = win.navigator.userAgent;

    // android webkit browser, non-chrome
    if( ua.indexOf( "Android" ) > -1 && ua.indexOf( "like Gecko" ) > -1 && ua.indexOf( "Chrome" ) === -1 ){
    fonts = ns.files.css.fontsTTF;
    }
    // old IE via html classname
    else if( win.document.documentElement.className.indexOf( "ie-lte8" ) > -1 ){
    fonts = ns.files.css.fontsEOT;
    }

    // Load the fonts via inject into head
    var injectref = win.document.getElementsByTagName( "script" )[ 0 ];

    function loadCSS( href ){
    var fontslink = win.document.createElement( "link" );
    fontslink.rel = "stylesheet";
    fontslink.href= href;
    if( injectref && injectref.parentNode ) {
    injectref.parentNode.insertBefore( fontslink, injectref );
    } else {
    // uncommon, but oldIE timing
    window.setTimeout(function() {
    loadCSS( href );
    }, 15);
    }
    }

    loadCSS( fonts );