Skip to content

Instantly share code, notes, and snippets.

@awestmoreland
Created July 11, 2013 14:42
Show Gist options
  • Save awestmoreland/5976065 to your computer and use it in GitHub Desktop.
Save awestmoreland/5976065 to your computer and use it in GitHub Desktop.
Load Typekit if fonts not already loaded
// Set kit ID
var typekitID = "tk999999";
var testFont = "wf-proximanova-n4-active";
// Wait... then load Typekit if font not active
setTimeout("addTypekit(typekitID);",3000);
function addTypekit(typekitID,testFont){
// If HTML element doesn't have font's success class, load Typekit
var htmlElement = document.getElementsByTagName("html")[0]
if((' ' + htmlElement.className + ' ').indexOf(' ' + testFont + ' ') == -1){
WebFontConfig = {
typekit: { id: typekitID }
};
(function() {
var wf = document.createElement('script');
wf.src = ('https:' == document.location.protocol ? 'https' : 'http') +
'://ajax.googleapis.com/ajax/libs/webfont/1.4.7/webfont.js';
wf.type = 'text/javascript';
wf.async = 'true';
var s = document.getElementsByTagName('script')[0];
s.parentNode.insertBefore(wf, s);
})();
console.log('font loaded by navbar');
}
else{
console.log('font loaded by page');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment