Skip to content

Instantly share code, notes, and snippets.

@RudolfHattenkofer
Created September 28, 2013 13:28
Show Gist options
  • Save RudolfHattenkofer/6742082 to your computer and use it in GitHub Desktop.
Save RudolfHattenkofer/6742082 to your computer and use it in GitHub Desktop.
Include Typkit in TinyMCE. Don't forget the Kit ID in line 9!
tinyMCE.init
setup: ( ed ) ->
ed.on 'PreInit', (e) ->
doc = ed.getDoc()
# Create the script we will add to the header asynchronously
jscript = "(function() {\n
var config = {\n
kitId: '######'\n
};\n
var d = false;\n
var tk = document.createElement('script');\n
tk.src = '//use.typekit.net/' + config.kitId + '.js';\n
tk.type = 'text/javascript';\n
tk.async = 'true';\n
tk.onload = tk.onreadystatechange = function() {\n
var rs = this.readyState;\n
if (d || rs && rs != 'complete' && rs != 'loaded') return;\n
d = true;\n
try { Typekit.load(config); } catch (e) {}\n
};\n
var s = document.getElementsByTagName('script')[0];\n
s.parentNode.insertBefore(tk, s);\n
})();"
# Create a script element and insert the TypeKit code into it
script = doc.createElement("script")
script.type = "text/javascript"
script.appendChild(doc.createTextNode(jscript))
# Add the script to the header
doc.getElementsByTagName('head')[0].appendChild(script)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment