Skip to content

Instantly share code, notes, and snippets.

@tomjn
Created September 10, 2012 10:22
Show Gist options
  • Select an option

  • Save tomjn/3690149 to your computer and use it in GitHub Desktop.

Select an option

Save tomjn/3690149 to your computer and use it in GitHub Desktop.

Revisions

  1. tomjn revised this gist Sep 10, 2012. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion typekit.editor.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,5 @@
    add_filter("mce_external_plugins", "tomjn_mce_external_plugins");
    function tomjn_mce_external_plugins($plugin_array){
    $plugin_array['typekit'] = get_template_directory_uri().'/typekit.tinymce.js';//('/ilc-syntax-buttons/ilcsyntax.js');
    $plugin_array['typekit'] = get_template_directory_uri().'/typekit.tinymce.js';
    return $plugin_array;
    }
  2. tomjn revised this gist Sep 10, 2012. 1 changed file with 0 additions and 2 deletions.
    2 changes: 0 additions & 2 deletions typekit.editor.php
    Original file line number Diff line number Diff line change
    @@ -1,5 +1,3 @@
    <?php

    add_filter("mce_external_plugins", "tomjn_mce_external_plugins");
    function tomjn_mce_external_plugins($plugin_array){
    $plugin_array['typekit'] = get_template_directory_uri().'/typekit.tinymce.js';//('/ilc-syntax-buttons/ilcsyntax.js');
  3. tomjn revised this gist Sep 10, 2012. 1 changed file with 7 additions and 0 deletions.
    7 changes: 7 additions & 0 deletions typekit.editor.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,7 @@
    <?php

    add_filter("mce_external_plugins", "tomjn_mce_external_plugins");
    function tomjn_mce_external_plugins($plugin_array){
    $plugin_array['typekit'] = get_template_directory_uri().'/typekit.tinymce.js';//('/ilc-syntax-buttons/ilcsyntax.js');
    return $plugin_array;
    }
  4. tomjn created this gist Sep 10, 2012.
    51 changes: 51 additions & 0 deletions typekit.tinymce.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,51 @@
    (function() {
    tinymce.create('tinymce.plugins.typekit', {
    init: function(ed, url) {
    ed.onPreInit.add(function(ed) {

    // Get the DOM document object for the IFRAME
    var doc = ed.getDoc();

    // Create the script we will add to the header asynchronously
    var jscript = "(function() {\n\
    var config = {\n\
    kitId: 'xxxxxxx'\n\
    };\n\
    var d = false;\n\
    var tk = document.createElement('script');\n\
    tk.src = '//use.typekit.net/' + config.kitId + '.js';\n\
    tk.type = 'text/javascript';\n\
    tk.async = 'true';\n\
    tk.onload = tk.onreadystatechange = function() {\n\
    var rs = this.readyState;\n\
    if (d || rs && rs != 'complete' && rs != 'loaded') return;\n\
    d = true;\n\
    try { Typekit.load(config); } catch (e) {}\n\
    };\n\
    var s = document.getElementsByTagName('script')[0];\n\
    s.parentNode.insertBefore(tk, s);\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);

    });

    },
    getInfo: function() {
    return {
    longname: 'TypeKit For TinyMCE',
    author: 'Tom J Nowell',
    authorurl: 'http://tomjn.com/',
    infourl: 'http://twitter.com/tarendai',
    version: "1.1"
    };
    }
    });
    tinymce.PluginManager.add('typekit', tinymce.plugins.typekit);
    })();