CKEditor instance already exists

前端 未结 30 3480
刺人心
刺人心 2020-11-27 11:24

I am using jquery dialogs to present forms (fetched via AJAX). On some forms I am using a CKEditor for the textareas. The editor displays fine on the first load.

Whe

30条回答
  •  一向
    一向 (楼主)
    2020-11-27 11:52

    CKeditor 4.2.1

    There is a lot of answers here but for me I needed something more (bit dirty too so if anyone can improve please do). For me MODALs where my issue.

    I was rendering the CKEditor in a modal, using Foundation. Ideally I would have destoryed the editor upon closing, however I didn't want to mess with Foundation.

    I called delete, I tried remove and another method but this was what I finally settled with.

    I was using textarea's to populate not DIVs.

    My Solution

    //hard code the DIV removal (due to duplication of CKeditors on page however they didn't work)
    
        $("#cke_myckeditorname").remove();
    
    
         if (CKEDITOR.instances['myckeditorname']) {
                    delete CKEDITOR.instances['myckeditorname'];
                    CKEDITOR.replace('myckeditorname', GetCKEditorSettings());
                } else {
                    CKEDITOR.replace('myckeditorname', GetCKEditorSettings());
                }
    

    this was my method to return my specific formatting, which you might not want.

        function GetCKEditorSettings()
        {
           return {
                        linkShowAdvancedTab: false,
                        linkShowTargetTab: false,
                        removePlugins: 'elementspath,magicline',
                        extraAllowedContent: 'hr blockquote div',
                        fontSize_sizes: 'small/8px;normal/12px;large/16px;larger/24px;huge/36px;',
                        toolbar: [
                            ['FontSize'],
                            ['Bold', 'Italic', 'Underline', '-', 'NumberedList', 'BulletedList', '-', 'Link', 'Unlink'],
                            ['Smiley']
                        ]
                    };
        }
    

提交回复
热议问题