Skip to content

Instantly share code, notes, and snippets.

@blove
Created October 23, 2013 21:30
Show Gist options
  • Save blove/7127110 to your computer and use it in GitHub Desktop.
Save blove/7127110 to your computer and use it in GitHub Desktop.
Load typekit asynchronously using jQuery using CoffeeScript
$ ->
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