Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Disable Whole Redactor.js WYSIWYG Editor

Like you can disable a <textarea disabled>...</textarea> component, I would like to disable a redactor editor, but still display it on my page.

I would expect Redactor to read the disabled attribute on the textarea I am initializing, and disable the editor as appropriate, but it does not work and creates a fully functional editor instead.

<textarea class="redactor" disabled></textarea>
...
<script type="text/javascript">
$(function () {
        $('.redactor').redactor();
});
</script>

Is there an additional API command or workaround I can use to create a disabled editor? An easy way to disable and enable it would be preferred. I can't seem to find anything in the Redactor documentation or API on how to do it.

I'm using Redactor 9.1.9, but am willing to upgrade if necessary. Thanks!

like image 725
Lea Avatar asked Apr 22 '15 01:04

Lea


1 Answers

If you want to disable the editor, please try to set the contenteditable attribute to false. If you check the source code in the browser (with Firebug for example), you will see that the div which wraps the editor has the contenteditable="true" attribute. So try to change this with jQuery for example:

$('.redactor-editor').attr('contenteditable', 'false');

or Angular (in my case):

angular.element('.redactor-editor').attr('contenteditable', 'false');

You can try to do this with a timeout in order to make sure the content from the editor is fully generated and you have access to its attributes.

like image 115
decebal Avatar answered Sep 28 '22 11:09

decebal