Skip to content

Instantly share code, notes, and snippets.

@blove
Created Oct 23, 2013
Embed
What would you like to do?
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