簡體   English   中英

動態加載tinymce

[英]Loading tinymce dynamically

當tinymce在頭上,並在dom之前加載時,一切正常。 但是,如果我嘗試使用ajax( jquery.getScript() )加載javascript,它將無法正常工作。 當用戶單擊內容區域時,我正在啟動tinymce,因此dom必須准備就緒。 我想在不更改tinymce代碼的情況下且不在head標簽中運行它,因為腳本約為65kb(壓縮)。 我的代碼如下所示:

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

找到了問題。 Tinymce嘗試從腳本標簽中獲取“ baseURL”,但是如果我將其動態加載,則沒有匹配項。 它遍歷頁面上的每個腳本元素,並像這樣檢查它:/ /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src) _ /tiny_mce(|_gzip|_jquery|_prototype|_full)(_dev|_src)?.js/.test(n.src) 所以我只是像這樣重寫了baseURL參數:tinyMCE.baseURL =“ http://mysite.com/path_to_tinymce/”; tinyMCE.init({...,...});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM