Last active
September 7, 2017 08:35
-
-
Save anakadote/621cda35284ab8dde9ce428778c118b6 to your computer and use it in GitHub Desktop.
A TinyMCE 4.* plugin to add support for Typekit fonts - place in a new folder at tinymce/plugins/typekit/ and replace kitId value. Don't forget to add "typekit" to your TinyMCE "plugins" config array.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
tinymce.PluginManager.add('typekit', function(editor) { | |
editor.on('init', function() { | |
// Get the DOM document object for the IFRAME | |
var doc = this.getDoc(); | |
// Create the script we will add to the header asynchronously | |
var jscript = "(function(d) {\n\ | |
var config = {\n\ | |
kitId: 'xxxxxxx',\n\ | |
scriptTimeout: 3000\n\ | |
},\n\ | |
h=d.documentElement,t=setTimeout(function(){h.className=h.className.replace(/\bwf-loading\b/g,'')+' wf-inactive';},config.scriptTimeout),tk=d.createElement('script'),f=false,s=d.getElementsByTagName('script')[0],a;h.className+=' wf-loading';tk.src='//use.typekit.net/'+config.kitId+'.js';tk.async=true;tk.onload=tk.onreadystatechange=function(){a=this.readyState;if(f||a&&a!='complete'&&a!='loaded')return;f=true;clearTimeout(t);try{Typekit.load(config)}catch(e){}};s.parentNode.insertBefore(tk,s)\n\})(document);\n\ | |
"; | |
// Create a script element and insert the TypeKit code into it | |
var 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