【问题标题】:Why does Tinymce fails to initiate once jquery dialog box is closed and reopened?为什么关闭并重新打开 jquery 对话框后 Tinymce 无法启动?
【发布时间】:2012-04-25 14:51:31
【问题描述】:

我有一个 jquery UI 对话框,里面有 tinymce,我第一次打开对话框时 tinymce 工作正常,但是一旦我关闭对话框并重新打开它,我会看到 tinymce 编辑器,但我无法在里面输入任何内容好像它被禁用了一样。

【问题讨论】:

  • 请附上您的代码...我的水晶球今天正在播放...

标签: jquery jquery-ui tinymce jquery-dialog


【解决方案1】:

这里的问题看起来很清楚。关闭 jQuery 对话框时,您没有正确关闭 tinymce 实例。

要关闭编辑器实例,请使用:

tinymce.execCommand('mceRemoveControl',true,'editor_id');

更新:您应该使用 document.ready - 函数不会延迟编辑器初始化太多(如果文档在 1.4 秒后加载 - 您会破坏 1.6 秒并保持用户等待):

$(document).ready(function() {

  g = {};

  g.oEditor = new tinymce.Editor (
    "notesComments",
    {
        // General options
        mode : "none",
        theme : "advanced",
        height : 350,
        plugins : "style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
        theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons3 : "undo,redo,|,sub,sup,|,charmap,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen|,nonbreaking,pagebreak,hr",
        theme_advanced_buttons4 :   "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote",
        theme_advanced_buttons5 :   "link,unlink,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons6 : "tablecontrols,|,removeformat,visualaid",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : false
    });

  g.oEditor.render();


});

【讨论】:

  • 我将它添加到我的 beforeclose 函数中,但它仍然不起作用
  • 是的,我这样做了,我认为这与 DOM 准备得不够快有关
【解决方案2】:

我已经通过延迟函数解决了这个问题:

setTimeout(function() {

g = {};

g.oEditor = new tinymce.Editor (
    "notesComments",
    {
        // General options
        mode : "none",
        theme : "advanced",
        height : 350,
        plugins : "style,layer,table,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

        // Theme options
        theme_advanced_buttons1 : "newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull",
        theme_advanced_buttons2 : "formatselect,fontselect,fontsizeselect",
        theme_advanced_buttons3 : "undo,redo,|,sub,sup,|,charmap,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen|,nonbreaking,pagebreak,hr",
        theme_advanced_buttons4 : "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote",
        theme_advanced_buttons5 : "link,unlink,image,cleanup,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
        theme_advanced_buttons6 : "tablecontrols,|,removeformat,visualaid",
        theme_advanced_toolbar_location : "top",
        theme_advanced_toolbar_align : "left",
        theme_advanced_statusbar_location : "bottom",
        theme_advanced_resizing : false
    });

g.oEditor.render();

}, 3000);

【讨论】:

  • 在这种情况下,您应该使用文档准备功能,以避免过多延迟初始化!查看我的编辑答案
【解决方案3】:

这个就像一个魅力:

if(tinyMCE.execCommand('mceRemoveEditor', false, 'editorId')) {
  // re-init..
}

我从this thread得到这个

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-04-28
    • 1970-01-01
    • 2012-05-31
    • 2010-09-26
    • 1970-01-01
    相关资源
    最近更新 更多