MCE5-如何在 Tinymce-5 中将图像作为自定义按钮图标?

MCE5- How to put any image as custom button icon in Tiny mce-5?

我正在使用 TinyMce-5,我必须向它添加一些自定义按钮,这些按钮工作得很好,但我不知道如何在这些按钮上添加图像作为图标,因为 fontawesomes 没有出现设置这些图标,所以我需要在按钮上放置一个 .png 图像作为图标。这是我在设置中使用的代码:参数

ed.ui.registry.addButton('alignTop', {
    image:'http://localhost/image-process/images/donut_PNG27.png',
    tooltip: 'Align box top',
    onAction: function () {
        $('.shape[data-active=me]').css('top','0px');
    }
});

这里是js代码

function fixTinyIcons(){
    if($('button[aria-label="Bend down text"]').length > 0 && $('button[aria-label="Bend down text"]').attr('data-bg') != 'done'){
    //console.log('1st found');
    $('button[aria-label="Bend down text"]').html('<img src="images/bottom-bend.jpg" style="height: 20px; width: 20px;">');
    $('button[aria-label="Bend down text"]').attr('data-bg','done');
    st_stop++;
}
$(document).ready(function(){
    WinIntervalCheck = setInterval(fixTinyIcons,100);

});

这里是图片说明

我不喜欢上面的解决方案,所以我尝试了下面的方法并且工作得很好!!!!!


ed.ui.registry.addButton('alignTop', {
    text: '<image src="http://localhost/image-process/images/donut_PNG27.png" style="height: 24px;width: 24px;padding: 3px 0px 0px 0px;"/ >',
    tooltip: 'Align box top',
    onAction: function () {
        $('.shape[data-active=me]').css('top','0px');
    }
});

虽然 addIcon API documentation 表示它用于注册 SVG 图标,但您可以将任何标记传递给它:

// works with tinymce v5.2
ed.ui.registry.addIcon('donut', '<img src="/image-process/images/donut_PNG27.png" />');

ed.ui.registry.addButton('alignTop', {
    icon: 'donut',
    ...
});