Skip to content

Instantly share code, notes, and snippets.

@joelpittet
Created June 4, 2015 22:44
Show Gist options
  • Save joelpittet/69c32c148e457bdd17fc to your computer and use it in GitHub Desktop.
Save joelpittet/69c32c148e457bdd17fc to your computer and use it in GitHub Desktop.
CKEditor + Typekit (BESbswy Fix)
var typkitID = 'XXXXXXX';
CKEDITOR.on('instanceReady',
function(ev) {
var $editor_instance = CKEDITOR.instances[ev.editor.name];
(function(d) {
try {
var config = {
kitId: typkitID,
scriptTimeout: 3000
},
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);
} catch(e) {}
})($editor_instance.document);
// Old method.
// var $script = document.createElement('script'),
// $editor_instance = CKEDITOR.instances[ev.editor.name];
// var protocol = (('https:' == document.location.protocol) ? 'https://' : 'http://');
// $script.src = protocol + 'use.typekit.com/' + typkitID + '.js';
// $script.onload = function() {
// try {
// $editor_instance.window.$.Typekit.load();
// } catch(e) {}
// };
// $editor_instance.document.getHead().$.appendChild($script);
}
);
@sockiplastsmurfen
Copy link

Hi Joel, could you please explain what you are doing here? :)

@joelpittet
Copy link
Author

Oh sure! I'm using TypeKit's advanced code, but the only difference is that I'm passing in the editors document object instead of the current page's document into the closure.

Voila it didn't have that BESbswy garbage generated.

Sorry for the delay responding, I didn't see this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment