How to remove tinymce editor buttons from Javascript?

醉酒当歌 提交于 2019-12-11 04:45:40

问题


I am using TinyMCE4.3.10 (as part of Wordpress 4.5.4). I create a custom tinymce editor using the code:

tinyMCE.execCommand("mceAddEditor", false, captionId);

tinyMCE.execCommand('mceAddControl', false, captionId);

"captionId" points to a textarea. Editor works fine but I want to remove few buttons. How do I do that ? I am not using tinyMCE.init() -- mainly because I don't know if I should be using it and editors works anyway.

I can disable using:

tinyMCE.get(captionId).controlManager.setDisabled('bold', true);

but I want to remove it.

Also, tinyMCE.get(captionId).controlManager.get('bold') returns undefined.

Any help is appreciated.


回答1:


You use tinymce.init({}) to invoke the editor with specific settings. If the ID of the <textarea> in question is contained in the variable captionId I would do this:

tinymce.init({
  selector: "#" + captionId,  //needs to be a string of the CSS selector for the ID
  .
  . 
  .
});  

This will target only that <textarea> for initialization. If you want to limit what options appear on the toolbar you can do so with the toolbar configuration option:

tinymce.init({
  selector: "#" + captionId,
  toolbar: [
    "table | insertfile undo redo | styleselect | bold italic",
    "removeformat | fontsizeselect | forecolor backcolor"a11ycheck
  ],
  . 
  .
});

https://www.tinymce.com/docs/configure/editor-appearance/#toolbar



来源:https://stackoverflow.com/questions/41042061/how-to-remove-tinymce-editor-buttons-from-javascript

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!