Skip to content

Instantly share code, notes, and snippets.

@ScottPolhemus
Last active May 9, 2016 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ScottPolhemus/d67cc90412764a8173d7836cd720d0a3 to your computer and use it in GitHub Desktop.
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).
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