public
Created

current font loading snippet

  • Download Gist
fonts.js
JavaScript
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 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 );

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.