How would I set tinymce to automatically set the editor as readonly if the textarea
already has the attr("readonly")
Use the checkbox to toggle between the "design" and "readonly" modes.
Use tinymce. remove() method to remove TinyMCE editor from the HTML element and again call tinymce. init() on the selector to reinitialize.
The TinyMCE editor can be made responsive by using css media queries. Simply add css rules that set the width property of table.
Selector engine, enables you to select controls by using CSS like expressions. We currently only support basic CSS expressions to reduce the size of the core and the ones we support should be enough for most cases.
A more general solution might be
tinyMCE.init({
...
setup: function(ed) {
if($('#'+ed.id).attr('readonly'))
ed.settings.readonly = true;
}
});
This will work for all textareas without you having to specify any ids. In addition it will actually set the editor to readonly mode, and not only prevent editing.
In case you have the following textarea
<textarea id="my_textarea_id" readonly="readonly">Some content here.</textarea>
you may save the knowledge of having a readonly attribute to a variable:
var readonly = $("textarea#my_textarea_id").attr("readonly") ? 1 : 0;
Now the tinymce init function. We choose mode none
to init the editor later.
tinyMCE.init({
theme : "advanced",
mode: 'none',
readonly : readonly,
...
});
Here, you can init your editor instance using the id of your textarea
tinyMCE.execCommand("mceAddControl", true, "my_textarea_id");
Your editor instance will be initialized as readonly.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With