简体   繁体   中英

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;
    }
};

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({ ..., ... });

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM