Created
October 23, 2013 21:30
-
-
Save blove/7127110 to your computer and use it in GitHub Desktop.
Load typekit asynchronously using jQuery using CoffeeScript
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
$ -> | |
class Brianflove | |
@_initialized = null | |
constructor: () -> | |
if @_initialized is not null | |
throw "Do not instantiate this class on your own" | |
@_initialized = true | |
initTypeKit: () -> | |
config = | |
kitId: 'your-id-goes-here' | |
scriptTimeout: 3000 | |
active: -> | |
$('.container h1, .container .lead').each -> | |
$(@).fadeIn 800 | |
$('html').addClass 'wf-loading' | |
t = setTimeout -> | |
$('html').removeClass 'wf-loading' | |
$('html').addClass 'wf-inactive' | |
, config.scriptTimeout | |
$.ajax | |
url: '//use.typekit.net/' + config.kitId + '.js' | |
dataType: 'script', | |
cache: true, | |
success: -> | |
clearTimeout t | |
try | |
Typekit.load config | |
catch | |
brianflove = new Brianflove | |
brianflove.initTypeKit()[/js] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment