Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

load tinymce on demand by using jquery

Tags:

jquery

tinymce

This is my script:

$.ajaxSetup({async: false});
$.getScript('http://www.mydomain.com/dev/js/tinymce/tiny_mce.js', function(){
    tinyMCE.init({
        document_base_url : "http://www.mydomain.com/dev/js/tinymce/",
        [...],
    });
});
$.ajaxSetup({async: true});

It load tiny_mce.js success. But when init tinymce in callback, tinymce load 2 following scripts with incorrect path:

http://www.mydomain.com/dev//langs/en.js
http://www.mydomain.com/dev//themes/advanced/editor_template.js

Even I use document_base_url or not, tinymce still load above path.

like image 835
StoneHeart Avatar asked Dec 17 '22 22:12

StoneHeart


2 Answers

I solved the problem as is written here: http://tinymce.moxiecode.com/forum/viewtopic.php?pid=23065#p23065

My script for dynamically loading tinyMCE via jQuery is now:

// JS_FOLDER = "http://mydomain.com/js"
function initTinyMCE(JS_FOLDER, selector)
{
    var path = JS_FOLDER + '/GlobalUI/tinymce';

    if (selector == undefined) selector = 'mceEditor';
    var initFunct = function() {
        tinyMCE.baseURL = path + '/jscripts/tiny_mce/'; // THE IMPORTANT LINE
        tinyMCE.init({
            mode: "specific_textareas",
            editor_selector: selector,
            width : "700px",
            theme: "advanced",

            theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,undo,redo,|,bullist,numlist,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect,forecolor,backcolor",
            theme_advanced_buttons2 : "",
            theme_advanced_buttons3 : "",
            theme_advanced_buttons4 : "",
            theme_advanced_resizing : true,

            // Example content CSS (should be your site CSS)
            content_css : path + "/css/custom_css.css"
        });
    }

    if(typeof tinyMCE == "undefined") {
        $.getScript(path + '/jscripts/tiny_mce/tiny_mce_src.js', function() {
            initFunct();
        });
    } else {
        initFunct();
    }         
like image 64
Martin Vseticka Avatar answered Dec 24 '22 21:12

Martin Vseticka


i am having this trouble too, after a day's work , i found a solution , just add this code before your tinymce.init() method:

 tinymce.dom.Event.domLoaded = true;

this would work on my case, may this help you too.

see here for more detail:tiny mce can't be inited when load js dynamically

like image 21
YuC Avatar answered Dec 24 '22 22:12

YuC