Kristian
Kristian

Reputation: 3461

Loading tinymce dynamically

When tinymce is in head, and loads before dom, all is ok. But if i'll try to load the javascript with ajax(jquery.getScript()) it does not work. I'm initalizing tinymce when user clicks the content area, so dom must be ready then. I'd like to get it working without altering tinymce code and not in head tag, cause the script is about 65kb(gzipped). My code looks like this:

window.tab_offers.show_edit = function() {
    if (init == true) {
        tinymce.execCommand('mceToggleEditor', false, 'offers-tab-content');
    } else {
        tinyMCE.init({
            mode : "exact",
            elements: "offers-tab-content",
            language : window.PAGE_LANG,
            theme : "advanced",
            content_css: site_url('css/parim/tinymce.css'),
            plugins : "autoresize",
            width: $('#offers-tab-content').width() + 18,
            theme_advanced_buttons1 : "cancelforecolor,backcolor,separator,bold,italic,underline,strikethrough,separator,bullist,numlist,separator,undo,redo,separator,hr,removeformat,separator,charmap,separator,link,unlink",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : ""
        });
    init = true;
    }
};

Upvotes: 2

Views: 1724

Answers (1)

Kristian
Kristian

Reputation: 3461

Found the problem. Tinymce tries to get "baseURL" from script tags, but if i'll load it dynamiclly, then there is no match. It iterates over every script element on page and check it like so: /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src). So i just overrided the baseURL parameter like so: tinyMCE.baseURL = "http://mysite.com/path_to_tinymce/"; tinyMCE.init({ ..., ... });

Upvotes: 4

Related Questions