简体   繁体   English

Tinymce只作为文本编辑器,没有编辑html

[英]Tinymce as text editor only, no editing html

I have a complex layout and dont want the client to be able to mess this up and end up breaking it. 我有一个复杂的布局,不希望客户端能够搞砸这个并最终打破它。 So I would like to restrict tinymce so that they can only edit/change the text. 所以我想限制tinymce,以便他们只能编辑/更改文本。

  • No changes would be allowed to the layouts 不允许对布局进行任何更改
  • No adding/removing anything apart from text 除了文本之外,不添加/删除任何内容
  • Literally all they can do is change the text. 他们所能做的就是改变文本。

Is this possible? 这可能吗?

I would say: "Yes, this is possible, depending on what you think which kind of actions a user may do." 我会说:“是的,这是可能的,这取决于你认为用户可能采取的行动。”

I assume your layout exists as html code and is to be found in the editor. 我假设您的布局存在为html代码,可以在编辑器中找到。 Now when a user starts selecting and deleting - that's a point where you will have to step in. You can write an own plugin (or a suitable setup config param with an onKeyUp handler) that checks if any of your valuable layout elements is gone. 现在,当用户开始选择和删除时 - 这是您必须介入的一个点。您可以编写自己的插件(或带有onKeyUp处理程序的合适的安装配置参数),以检查是否有任何有价值的布局元素消失。 If thats the case you will need to fix it. 如果是这种情况,您将需要修复它。 You can also check for the keycodes (ctrl+x, DELTE, Backspace, aso.). 您还可以检查密钥代码(ctrl + x,DELTE,Backspace,aso。)。 Copying into the editor would need to be restricted to text too (there are several SO questions regarding this problem). 复制到编辑器中也需要限制在文本中(关于这个问题有几个SO问题)。

TinyMce has a plugin for it. TinyMce有一个插件。 It is called noneditable : https://www.tinymce.com/docs/plugins/noneditable/ 它被称为不可编辑https//www.tinymce.com/docs/plugins/noneditable/

You can initiate tinymce like this: 你可以像这样启动tinymce:

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 have to define both attributes - I tried only with noneditable_editable_class counting on it will take the rest as not editable - without success. 你必须定义这两个属性 - 我只尝试使用noneditable_editable_class计算它将其余部分视为不可编辑 - 没有成功。

The other solution (without tinyMce) would be placing contenteditable attribute on the page elements you wish to be allowed to edit: 另一个解决方案 (没有tinyMce)将在您希望允许编辑的页面元素上放置contenteditable属性:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM