Created
July 11, 2013 14:42
-
-
Save awestmoreland/5976065 to your computer and use it in GitHub Desktop.
Load Typekit if fonts not already loaded
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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