TinyMCE更改现有按钮图标

时间:2017-01-26 12:19:08

标签: javascript jquery tinymce wysiwyg

我在我的html表单中使用了TinyMCE WYSIWYG编辑器。我想更改现有工具栏按钮的图标(16x16图像),即粗体按钮,斜体按钮等。想法是放置我自己的图纸而不是基本 B I 等图标。

我找到了如何通过tinymce.Editor.addButton('myButton', {... 'image': '/path/to/my/drawing'})方法将自定义图标添加到工具栏的全新按钮,但我仍然不知道如何替换现有按钮的图标。

3 个答案:

答案 0 :(得分:0)

答案 1 :(得分:0)

我找到了解决方案,但可能你知道更简单的方法,所以随时回答。

可以通过为TinyMCE创建自己的皮肤来完成。但是皮肤看起来不容易创建,而TinyMCESkinCreator似乎对深度定制没有帮助。所以我发现cool third-party skin有明显的存储这些图标的地方 - img/sprites16px.png。所以我能够在图形编辑器中重绘它们。

我通过编辑spritelist成功地将 B 字母替换为粗体俄语字母Ж

my result

答案 2 :(得分:0)

TinyMce v5的CSS(在IE 11,Firefox 67.x和Chrome 74上运行)的另一种解决方案:

Image example

请注意,Gras中的...[aria-label="Gras"]一词是翻译的结果,因此您必须在自己的代码中对其进行更改。

    /*Hide original svg:*/
    .tox-tbtn[aria-label="Gras"] .tox-icon svg {
        display: none;
    }

    /*Dimensions of svg icon:*/
    .tox-tbtn[aria-label="Gras"] .tox-icon {
        display: list-item;
        list-style: none;
        width: 18px;
        height: 18px;
    }

    /*Svg icon:*/
    [aria-label='Gras'].tox-tbtn .tox-icon {
        background-image: url("/build/admin/images/tinyMceBoutonGras.svg");
        background-repeat: no-repeat;
        background-position: center center;
    }

这里,与SVG相同的示例在Base64中进行转换:

    /*Hide original svg:*/
    .tox-tbtn[aria-label="Gras"] .tox-icon svg {
        display: none;
    }

    /*Dimensions of svg icon:*/
    .tox-tbtn[aria-label="Gras"] .tox-icon {
        display: list-item;
        list-style: none;
        width: 18px;
        height: 18px;
    }

    /*Svg icon (In base64):*/
    [aria-label='Gras'].tox-tbtn .tox-icon {
        background-image: url(data:image/svg+xml;base64,PD94bWwg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