1
votes

I'm having difficulty disabling certain CKEditor buttons. Basically, I'd like to loop through all of the loaded commands and disable them at runtime so that they are represented as greyed out buttons. Here is my code for doing this:

for (var key in CKEDITOR.instances.editor1.commands) {
        if (CKEDITOR.instances.editor1.commands.hasOwnProperty(key)) {
            console.log("disabling command " + key);
            CKEDITOR.instances.editor1.commands[key].disable();
        }
    }

My CKEditor setup uses the Image, Background Colour, Bold, Italic, Underline, Insert/Remove Bulleted List, Copy and Paste plugins. However, the only button that is actually disabled via this method is the Image button; the others remain enabled, even though I see no errors and my console.log is firing for each of them.

Any advice would be greatly appreciated.

1

1 Answers

2
votes

It's tricky what you want to do. Even if disabled, some commands (context sensitive ones) will immediately re-enable on selectionChange event because they observe user actions and check whether they're applicable considering current selection (i.e. cut command waits for some non-collapsed selection to be created).

If you want to disable editing totally, you should use editor.setReadOnly(). However if you want to disable commands and let users type, some hacking will be needed because this is quite the opposite of what WYSIWYG editors are for.