简体   繁体   English

动态加载tinymce

[英]Loading tinymce dynamically

When tinymce is in head, and loads before dom, all is ok. 当tinymce在头上,并在dom之前加载时,一切正常。 But if i'll try to load the javascript with ajax( jquery.getScript() ) it does not work. 但是,如果我尝试使用ajax( jquery.getScript() )加载javascript,它将无法正常工作。 I'm initalizing tinymce when user clicks the content area, so dom must be ready then. 当用户单击内容区域时,我正在启动tinymce,因此dom必须准备就绪。 I'd like to get it working without altering tinymce code and not in head tag, cause the script is about 65kb(gzipped). 我想在不更改tinymce代码的情况下且不在head标签中运行它,因为脚本约为65kb(压缩)。 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. Tinymce尝试从脚本标签中获取“ baseURL”,但是如果我将其动态加载,则没有匹配项。 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) . 它遍历页面上的每个脚本元素,并像这样检查它:/ /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src) _ /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/"; 所以我只是像这样重写了baseURL参数:tinyMCE.baseURL =“ http://mysite.com/path_to_tinymce/”; tinyMCE.init({ ..., ... }); tinyMCE.init({...,...});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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