Skip to content

Instantly share code, notes, and snippets.

@thomasgriffin
Last active August 29, 2015 14:12
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save thomasgriffin/afafa8eb35df9192ca60 to your computer and use it in GitHub Desktop.
Save thomasgriffin/afafa8eb35df9192ca60 to your computer and use it in GitHub Desktop.
(function() {
tinymce.create('tinymce.plugins.typekit', {
init: function(ed, url) {
ed.onPreInit.add(function(ed) {
// Get the iframe.
var doc = ed.getDoc();
// Create the script to inject into the header asynchronously.
var typekit = 'xxxxxx', // PLACE YOUR TYPEKIT KIT ID HERE!
jscript = "!function(){var t={kitId:\"" + typekit + "\"},e=!1,a=document.createElement(\"script\");a.src=\"//use.typekit.net/\"+t.kitId+\".js\",a.type=\"text/javascript\",a.async=\"true\",a.onload=a.onreadystatechange=function(){var a=this.readyState;if(!(e||a&&\"complete\"!=a&&\"loaded\"!=a)){e=!0;try{Typekit.load(t)}catch(c){}}};var c=document.getElementsByTagName(\"script\")[0];c.parentNode.insertBefore(a,c)}();";
// Create a DOM script element and insert the code inside of it.
var script = doc.createElement("script");
script.type = "text/javascript";
script.appendChild(doc.createTextNode(jscript));
// Append the srcript to the header.
doc.getElementsByTagName('head')[0].appendChild(script);
});
},
getInfo: function() {
return {
longname: 'TypeKit',
author: 'Thomas Griffin',
authorurl: 'https://thomasgriffin.io',
infourl: 'https://twitter.com/jthomasgriffin',
version: '1.0'
};
}
});
tinymce.PluginManager.add('typekit', tinymce.plugins.typekit);
})();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment