rysv
rysv

Reputation: 3440

How to remove tinymce editor buttons from Javascript?

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.

Upvotes: 1

Views: 1952

Answers (1)

Michael Fromin
Michael Fromin

Reputation: 13744

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

Upvotes: 2

Related Questions