How to add custom class addButton() on custom button in TinyMCE 4


Raichu

I want to add custom class on custom button in tinyMCE addButton() function.

E.g

editor.addButton('keywords', {
              text: 'Insert Keywords',
              class: 'MyCoolBtn', 
              icon: false,
              onclick: function () {

                  if($(this.id).hasClass("mce-active"))
                      EditorMethods.removeKeywordsToolbar(this.id);
                  else
                      EditorMethods.displayKeywordsToolbar(this.id);  
              }
          });

This doesn't work for me. TinyMCE JS adds a unique ID and some classes on the div containing the button. I want to add my custom class along with other classes on that div.

The current HTML for the button is

 <div aria-labelledby="mceu_35" tabindex="-1" class="mce-widget mce-btn mce-first mce-last mce-btn-has-text mce-active" id="mceu_35" role="button"> <button tabindex="-1" type="button" role="presentation"> <span class="mce-txt">Insert Keywords</span> </button> </div>

Please suggest a way to get the div ID or insert a class on the div containing the button.

Markas

Just write the class names with spaces between them.

editor.addButton( 'ampforwp_tc_button', {
        text: 'Copy The Content',
        icon: 'dashicons dashicons-clipboard',
        classes: 'ampforwp-copy-content-button ', 
        tooltip: 'Copy The Content from Main Editor', 
        onclick: function() {
            editor.insertContent(tinymce.editors.content.getContent());
        } 
});

But it will automatically add mce- before every custom class you provide. So to add CSS use classes like:

.mce-ampforwp-copy-content-button

It will definitely solve the problem as I did.

Related


How to add custom button in ACF Wysiwyg tinymce?

PHP work I need to add custom button to toolbar ACF Wysiwyg tinymce. I use the following code: tinymce.PluginManager.add( 'wdd_mce_format', function ( editor, url ) { editor.addButton( 'wdd_mce_format', { active: true, tooltip: 'Formating t

How to add custom button in ACF Wysiwyg tinymce?

PHP work I need to add custom button to toolbar ACF Wysiwyg tinymce. I use the following code: tinymce.PluginManager.add( 'wdd_mce_format', function ( editor, url ) { editor.addButton( 'wdd_mce_format', { active: true, tooltip: 'Formating t

How to add custom button in ACF Wysiwyg tinymce?

PHP work I need to add custom button to toolbar ACF Wysiwyg tinymce. I use the following code: tinymce.PluginManager.add( 'wdd_mce_format', function ( editor, url ) { editor.addButton( 'wdd_mce_format', { active: true, tooltip: 'Formating t

How to add custom button in ACF Wysiwyg tinymce?

PHP work I need to add custom button to toolbar ACF Wysiwyg tinymce. I use the following code: tinymce.PluginManager.add( 'wdd_mce_format', function ( editor, url ) { editor.addButton( 'wdd_mce_format', { active: true, tooltip: 'Formating t

How to add custom button in ACF Wysiwyg tinymce?

PHP work I need to add custom button to toolbar ACF Wysiwyg tinymce. I use the following code: tinymce.PluginManager.add( 'wdd_mce_format', function ( editor, url ) { editor.addButton( 'wdd_mce_format', { active: true, tooltip: 'Formating t

How to add custom button in ACF Wysiwyg tinymce?

PHP work I need to add custom button to toolbar ACF Wysiwyg tinymce. I use the following code: tinymce.PluginManager.add( 'wdd_mce_format', function ( editor, url ) { editor.addButton( 'wdd_mce_format', { active: true, tooltip: 'Formating t

Add custom icon to tinyMCE button

captis I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE, thus: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not accep

Add custom icon to tinyMCE button

captiz I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not acceptable,

Add custom icon to tinyMCE button

captis I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE, thus: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not accep

Add custom icon to tinyMCE button

captis I'm trying to add a Font-Awsome icon to a button I've added to tinyMCE, thus: ed.addButton('youtube', { title: 'Add Video' , icon: 'icon-youtube', onclick: function () { //do stuff here... } Using images like the docs is not accep

How to add custom block in tinyMce

Tariq Hussein I want to add a custom format block for TinyMCE, I was able to do it using the following code. style_formats: [ {title : 'Code', block : 'pre', classes : 'pre-code', exact: true},] https://codepen.io/anon/pen/vWRGEg However, by adding this code,

How to add custom block in tinyMce

Tariq Hussein I want to add a custom format block for TinyMCE, I was able to do it using the following code. style_formats: [ {title : 'Code', block : 'pre', classes : 'pre-code', exact: true},] https://codepen.io/anon/pen/vWRGEg However, by adding this code,