TinyMCE and JQuery dialog: TinyMCE read only when

2019-05-15 10:31发布

I am using the TinyMCD plugin in the Dialog plugin.

Everything works fine, until I set the dialog's modal parameter to true. When I am doing that, the TinyMCE textarea works fine only the first time the dialog is opened and then becomes read only.

Here is the example of my code:

tinyMCE.init({ mode: 'none' });
        var dlgComments = $('#dlgInternalComments');
        if (dlgComments.length == 0)
        {
            dlgComments = $('<div/>').attr('id', 'dlgInternalComments'),
                txtAreaComments = $('<textarea/>').attr('id', 'txtInternalComments').appendTo(dlgComments);

            dlgComments.dialog({
                height: 300,
                width: 800,
                modal:true,
                open: function ()
                {
                    if ($('#txtInternalComments_parent', $(this)).length == 0)
                    {
                        var ddd = {mode:'none'}; //$.extend({}, Globals.RichTextBox, { mode: 'none' });
                        txtAreaComments.tinymce(ddd);
                    }
                },
                buttons: {
                    'Parse': function ()
                    {
                        processAuthorsParagraph();
                        $(this).dialog('close');
                    }
                }
            });
        }
        else
        {
            dlgComments.dialog('open');
        }

I don't know how to fix this issue. I have tryed some suggestions from here: http://www.codestumps.com/2011/05/adding-tinymce-into-a-jquery-ui-dialog/ but I haven't found the solution.

If you can help me, thank you very much.

1条回答
乱世女痞
2楼-- · 2019-05-15 10:45

Problem resolved, here is the full working code:

function removeTinyMCE () {
    tinyMCE.execCommand('mceFocus', false, 'dialog-modal');
    tinyMCE.execCommand('mceRemoveControl', false, 'dialog-modal');
}

function addTinyMCE() {
    jQuery('#dialog-modal').tinymce({
        script_url: '/js/tiny_mce_3.2.7_jquery/jscripts/tiny_mce/tiny_mce.js',
        width: "800px",
        mode: "textarea",
        theme : "simple",
    });
}

function addAuto()
{
    $('#dialog-modal').dialog({
        autoOpen: true,
        modal: true,
        title: "Email Dialog",
        open: addTinyMCE,
        close: function() {
            removeTinyMCE();
            $(this).dialog('destroy');
        },
        buttons:  {
            'Cancel': function() {
                processAuthorsParagraph();
                removeTinyMCE();
                $(this).dialog('destroy');   
            }
        }
    });
}

And the html for the dialog is:

<div style="display: none"; id="dialog-modal" title="Basic modal dialog" style="display: none" ></div> 
查看更多
登录 后发表回答