jquery - 完全删除 JQuery tinyMCE

标签 jquery tinymce

我已经像这样初始化了tinyMCE:

$('#text').tinymce({
    // Location of TinyMCE script, optional, already loaded in page.
    script_url : '../adminContent/js/tiny_mce/tiny_mce.js',

    // General options
    theme : "advanced",
    plugins : "table,advimage,advlink,iespell,inlinepopups,preview,contextmenu,paste,visualchars",

    // Theme options
    theme_advanced_buttons1 : "bold,italic,underline,strikethrough,|,forecolor,|,justifyleft,justifycenter,justifyright,justifyfull,formatselect,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image",
    theme_advanced_buttons2 : "cut,copy,paste,pastetext,pasteword,|,removeformat,cleanup,code,|,preview,tablecontrols,|,hr,visualaid,|,charmap,iespell",
    theme_advanced_buttons3 : "",

    theme_advanced_toolbar_location : "top",
    theme_advanced_toolbar_align : "left",
    theme_advanced_statusbar_location : "bottom",
    theme_advanced_resizing : true
});

上面的代码完美运行。问题是当我尝试删除tinyMCE时。

我的删除代码是:

$('#text').tinymce().execCommand('mceRemoveControl', false, 'text');

我也尝试过:

$('#text').remove();

$('#text').tinymce().remove();

第一个似乎没有做任何事情。最后两个给我这个错误:

Uncaught ReferenceError: t is not defined

虽然tinymce是由HTML文档加载的,但我正在使用以下方式加载另一个脚本:

$.getScript(viewPath + '/mod/adminContent/js/editContent.js', function(){
    initEditContent(popup);
});

popup 是对加载tinymce 的弹出窗口的引用。它只是一个使用 jquery 创建的 div。 div 的内容是使用 jquery ajax 加载的。

editContent.js 看起来像这样:

var contentID;
function initEditContent(popup){
    contentID = $('#contentID').val();

    tinyMCE.execCommand("mceAddControl", true, 'text');

    setTimeout(reposition, 50);
    setTimeout(reposition, 150);
    setTimeout(reposition, 250);

    // Submit form
    $('#editTextForm').ajaxForm(
    {
        // Before submit
        beforeSubmit: function(){
            //setPopupMessage(popup, '<div id="loading"><img src="../../img/loading.gif" />&nbsp;Please wait...</div>');
        },

        // Once submit completed
        success: function(responseText){
            tinyMCE.execCommand("mceRemoveControl", true, 'text');
            //closePopup(popup);

            // Update button with new data
            $('#' + contentID).html(responseText);
        }
    });
}

最佳答案

这看起来像是自 3.5b3 版本以来tinyMCE 的问题。它适用于版本 3.5b2。

参见my fiddle示例。

您会注意到它加载和卸载正常。但是将版本更改为edge或3.5b3,卸载时就会出现错误。

tinyMCE bug site 上所述:

Description of problem:

Javascript error on line 13518. t is not defined.

Steps to reproduce:

  1. Call tinyMCE.execCommand('mceRemoveControl', false, idOfTextarea);

Problem:

In 3.5b3 you renamed t to self, but didn't rename the used variable in the same line to get the doc.

Solution:

Change line 13518 (in function hide()) to: var self = this, doc = self.getDoc();

关于jquery - 完全删除 JQuery tinyMCE,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10073625/

相关文章:

javascript - 回调为 num_rows 并在语句满足时中断

wordpress - 如何在WP中的TinyMCE中添加多个按钮?

html - TinyMCE 4 不断删除背景大小

javascript - 访问深层 json 链接以进行重定向

jQuery .html() 不适用于隐藏的 div?

jquery - 如何通过 jquery 选中/取消选中多级复选框

javascript - ajax 调用后 PHP header 重定向没有设置 $_SESSION 变量

javascript - 插入/上传图像到tinyMCE 4.X

jquery-ui - 如果不在初始选择的选项卡上,jQuery UI 选项卡中的 TinyMCE 的大小在 ui 选项卡中的大小不正确(jsFiddle 示例)

javascript - TinyMCE Spellchecker Rails 不工作