Created
December 27, 2014 00:46
-
-
Save thomasgriffin/ca6b461de1bb4b796a0e to your computer and use it in GitHub Desktop.
Load a TypeKit Font Kit inside of the TinyMCE Visual Editor in WordPress.
This file contains 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
(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 jscript = "(function() { | |
var config = { | |
kitId: 'gcc4mmp' // YOUR TYPEKIT ID GOES HERE INSIDE THE SINGLE QUOTES. | |
}; | |
var d = false, | |
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); | |
})();"; | |
// 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
You just solved my biggest issue ever occured! Big thanks 👍