Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Turning CKEditor 4 inline editing on and off with JavaScript

I need to be able to toggle inline editing on/off with a button. See here for example of inline editing: http://nightly-v4.ckeditor.com/3559/samples/inlineall.html

My markup is as so:

<div contenteditable='true'>Mycontent</div>

Using jQuery I want to be able to turn on/off the editor.

I have tried setting contenteditable to false, but this does not work. The editor is not loading back into the page on toggling the contenteditable setting.

Addendum: I also needed to destroy all CKEditor inline instances on a button click. Here is how I did that:

        //kill all ckeditors
        for(k in CKEDITOR.instances){
            var instance = CKEDITOR.instances[k];
            instance.destroy();
        }
like image 279
izip Avatar asked Oct 11 '12 18:10

izip


1 Answers

jQuery won't help you. Use CKEditor's API. E.g. you can destroy editor each time you want to turn it off (see http://nightly-v4.ckeditor.com/ckeditor_api/#!/api/CKEDITOR.editor-method-destroy) and initialize again to turn it on. There may be other ways to "turn editor off", but you'd have to be more precise what does it mean for you.

like image 119
Reinmar Avatar answered Oct 01 '22 21:10

Reinmar