Skip to content

Instantly share code, notes, and snippets.

@arghav
Created February 5, 2013 06:31
Show Gist options
  • Save arghav/4712669 to your computer and use it in GitHub Desktop.
Save arghav/4712669 to your computer and use it in GitHub Desktop.
Load typekit on EpicEditor
editor.on('load', function () {
// Step 1: Grab the editor element
var editorDoc = editor.getElement('editor');
// Step 2: Create the script tag
var script = editorDoc.createElement('script');
script.type = 'text/javascript';
script.innerHTML = "(function() {var config = {kitId: '<yourKitID>'}; var d = false; var tk = document.createElement('script'); tk.src = '//use.typekit.net/' + config.kitId + '.js'; tk.type = 'text/javascript'; tk.async = 'true'; tk.onload = tk.onreadystatechange = function() {var rs = this.readyState; if (d || rs && rs != 'complete' && rs != 'loaded') return; d = true; try { Typekit.load(config); } catch (e) {} }; var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(tk, s); })();";
// Step 3: Add it to the editor's <head>
var editorHead = editorDoc.getElementsByTagName('head')[0];
editorHead.appendChild(script);
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment