Inline CKEditor with toolbar on generated code

流过昼夜 提交于 2019-12-06 11:55:25

During the initialization phase CKEditor checks whether there's an editor instance already bound to the element. The error you get suggests that you're providing an id of the element that hasn't been yet attached to DOM or it was removed from DOM before inline() is called.

Make sure that the order is correct:

<div id="editable" contenteditable="true">
    <h4>{{title}}</h4>
    {{text}}
</div>

<script>
   CKEDITOR.disableAutoInline = true;
   CKEDITOR.inline( 'editable' );
</script>

Is <div id="editable" contenteditable="true">...</div> generated by JavaScript? If so, make sure that inline() is called after the element is injected into DOM.

"Last hope" suggestion: Do you call inline() from different DOM scope (i.e. iframe window)?

Thanks for the answer oleq.

Yes, the problem was that the content was being inserted after ckeditor was loaded. I also had a problem with Google Chrome greying out the toolbar.

To solve both problems I used the following code after inserting new content :

$('.editable').click(function() {
    var name;
    for(name in CKEDITOR.instances) {
        var instance = CKEDITOR.instances[name];
        if(this && this == instance.element.$) {
            return;
        }
    }
    $(this).attr('contenteditable', true);
    CKEDITOR.inline(this);
});
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!