Tinymce only as a text editor, no html editing

I have a complicated layout and I do not want the client to spoil it and eventually break it. Therefore, I would like to restrict tinymce so that they can only edit or modify text.

  • Changes to layouts will not be allowed.
  • No add / remove anything other than text
  • Literally all they can do is change the text.

Is it possible?

+4
source share
2 answers

I would say: "Yes, it is possible, depending on what you think about what actions the user can do."

I assume that your layout exists as html code and is in an editor. Now that the user begins to select and delete, this is the point at which you will need to enter. You can write your own plugin (or a suitable configuration configuration parameter with the onKeyUp handler) that checks to see if any of your valuable layout elements have disappeared. If so, you will need to fix it. You can also check key codes (ctrl + x, DELTE, Backspace, aso.). Copying to the editor should also be limited to text (there are several questions related to this problem).

0
source

TinyMce has a plugin for it. It is called immutable : https://www.tinymce.com/docs/plugins/noneditable/

You can initiate tinymce as follows:

tinymce.init({ selector: 'texteditor', // change this value according to your HTML toolbar: 'undo redo', // disable most of the plugins ... context_menu: false, menubar: false, // ... to allow text edit only noneditable_editable_class: "editable", // class allowed to edit noneditable_noneditable_class: "non_editable" // the parent (everything else) }); 

You must define both attributes - I tried only with noneditable_editable_class , assuming that this leaves unchanged - without success.

Another solution (without tinyMce) would be to place the contenteditable attribute on the page elements you want to allow:

 $('.editable').attr('contenteditable','true'); 
0
source

All Articles