Last active
May 9, 2016 15:49
-
-
Save ScottPolhemus/d67cc90412764a8173d7836cd720d0a3 to your computer and use it in GitHub Desktop.
Fires a custom event on the page as soon as Typekit finishes loading or fails to load. Add this in place of the standard Typekit.load() snippet to enable listening for the event in your own JS (useful for controlling how text appears on page load).
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
function triggerTypekitFinish() { | |
if (typeof window.CustomEvent === 'function') { | |
var event = new CustomEvent('typekit-finish'); | |
} else { | |
var event = document.createEvent('CustomEvent'); | |
event.initCustomEvent('typekit-finish', true, true, {}); | |
} | |
document.documentElement.dispatchEvent(event); | |
} | |
try { | |
Typekit.load({ | |
active: triggerTypekitFinish, | |
inactive: triggerTypekitFinish | |
}); | |
} catch(e) { | |
triggerTypekitFinish(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment