TinyMce set editor button text color

I have some custom buttons that I want the text of each button to be different. However, the style option sets the style to a div, not a button, so it doesn't work.

Here is my code for creating a button

// Add a button for rank
editor.addButton('rank', {
    text: 'Rank',
    tooltip: 'Highlight Rank',
    icon: false,
    style:'color:red;',
    onPostRender: function () {
        var button = this;
        editor.on('NodeChange', function (e) {
            if (editor.formatter.match('rank')) {
                button.active(true);
            } else {
                button.active(false);
            }
        });
    },

Here is the html output

<div id="mceu_0" class="mce-widget mce-btn mce-btn-small mce-first mce-last" tabindex="-1" aria-labelledby="mceu_0" style="color: red;" role="button" aria-label="Highlight Rank" aria-pressed="false">

<button role="presentation" type="button" tabindex="-1" >Rank</button></div>

Can someone tell me the correct option to apply the style to the button? I need to style each button differently.

0
source share
1 answer

You can create a CSS class with descendant or child on the buttons and apply it by setting the TinyMCE button classes :

tinymce.init({
    selector: "textarea",
    toolbar: "rank",
    setup: function (editor) {
        editor.addButton('rank', {
            text: 'Rank',
            tooltip: 'Highlight Rank',
            icon: false,
            classes: 'rank-button'
        });
    }
});
.mce-rank-button button {
  color: red !important;
}
<script src="http://tinymce.cachefly.net/4.2/tinymce.min.js"></script>
<form method="post" action="somepage">
    <textarea name="content" style="width:100%"></textarea>
</form>
Run codeHide result
+1
source

Source: https://habr.com/ru/post/1599342/


All Articles