How to add toolbar button in custom tinymce dropdown menu?


Mint departure

I created a custom dropdown in tinymce like this:

tinymce.init({
    toolbar: "alignment",

    setup: function(editor) {
        editor.addButton('alignment', {
            type: 'menubutton',
            text: 'Alignment',
            icon: false,
            menu: [
                { text: 'left', onclick: function() {tinymce.activeEditor.formatter.toggle('alignleft');}},
                { text: 'center', onclick: function() {tinymce.activeEditor.formatter.toggle('aligncenter');}},
                { text: 'right', onclick: function() {tinymce.activeEditor.formatter.toggle('alignright');}},
                { text: 'justify', onclick: function() {tinymce.activeEditor.formatter.toggle('alignjustify');}},
            ]
        });

    }

});

This creates this:

tinymce dropdown

However, all I want is to move the alignment button from the main toolbar of the dropdown.

How can I put these actual buttons from the toolbar into the dropdown menu? Like the code above or a completely different way?

Align buttonSo basically put those buttons in the dropdown above, while setting the switch state to on and off.

sbedulin

Try this setup - Plunker

tinymce.init({
    selector: "textarea",
    toolbar: "styleselect | bold italic | alignment | alignmentv2",
    setup: function(editor) {
      editor.addButton('alignment', {
          type: 'listbox',
          text: 'Alignment',
          icon: false,
          onselect: function(e) {
            tinyMCE.execCommand(this.value());
          },
          values: [
              {icon: 'alignleft', value: 'JustifyLeft'},
              {icon: 'alignright', value: 'JustifyRight'},
              {icon: 'aligncenter', value: 'JustifyCenter'},
              {icon: 'alignjustify', value: 'JustifyFull'},
          ],
          onPostRender: function() {
            // Select the firts item by default
            this.value('JustifyLeft');
          }
      });

      editor.addButton('alignmentv2', {
            type: 'menubutton',
            text: 'Alignment v2',
            icon: false,
            menu: [
                {icon: 'alignleft', onclick: function() { console.log(editor); tinyMCE.execCommand('JustifyLeft'); }},
                {icon: 'alignright', onclick: function() { tinyMCE.execCommand('JustifyRight'); }}
            ]
        });
    }
});

Related


Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") like the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentation <h4

Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") like the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentation <h4

Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") like the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentation <h4

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 icon to TinyMCE custom menu

work for life I'm modifying a plugin that adds a custom TinyMCE menu in WP. I need to be able to add icons to dropdown menu items and submenu items. I have icons enabled, which add space to it in the HTML, but can't figure out where JS can put them in. createC

Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") as shown in the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentat

Add icon to TinyMCE custom menu

work for life I'm modifying a plugin that adds a custom TinyMCE menu in WP. I need to be able to add icons to dropdown menu items and submenu items. I have icons enabled, which add space to it in the HTML, but can't figure out where JS can put them in. createC

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 change text in toolbar menu button item in tinymce 5?

David I recently migrated from tinymce 4 to tinymce 5, but I don't know how to create a dropdown menu (like a button) and change its text based on the current selection. Basically, I want something like a default font or a title button. This is how I create a

Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") like the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentation <h4

Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") like the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentation <h4

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

Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") as shown in the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentat

Is it possible to add custom button to select dropdown menu?

Terrence Jackson Is it possible to add custom buttons ("OK" and "Cancel") as shown in the image below, so that in the multi-selection pad dropdown, the user doesn't have to click outside the box to close the dropdown? I don't see this in the angular documentat

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 icon to TinyMCE custom menu

work for life I'm modifying a plugin that adds a custom TinyMCE menu in WP. I need to be able to add icons to dropdown menu items and submenu items. I have icons enabled, which add space to it in the HTML, but can't figure out where JS can put them in. createC