I have custom format in my formats dropdown, which works well. How do i add this format as a button to my toolbar?

my custom format looks like

custom_caption: {title: 'image caption', inline: 'span', classes: 'caption'}

i tried to add to

toolbar: 'someb_default_buttons | custom_caption'

but that didnt work

What am i doing wrong?

有帮助吗?

解决方案

You can do it like this:

tinymce.init({
    selector: "textarea",
    toolbar: "customFormat",
    setup: function(editor) {
        editor.addButton('customFormat', {
            text: 'My custom formatting',
            icon: false,
            onclick: function() {
                // Add the custom formatting
                editor.formatter.toggle('custom_caption');
            }
        });
    }
});

update

Have a look at this fiddle

I gues this is what you want. With this fiddle you can select some text, hit the My Custom Formatting button, and the text will be surrounded with a <span class="caption">.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top