切换工具栏按钮状态的最简单方法是什么(就像它与默认的粗体按钮一起使用)?我无法“获取”到将按钮外观从默认更改为选定的 Tinymce 类。这是我的插件代码(简化):

tinymce.PluginManager.add('myplugin', function (editor) {
    editor.addButton('mybutton', {
        text: false,
        image: 'someimage.png',

        onclick: function () {
            /* Toggle this toolbar button state to selected (like with the tinymce bold-button)*/
            /* and of course some other code goes here */
        }
    });
});

最佳答案

在 TinyMCE 4 中,您可以使用更简单的 stateSelector 设置:

editor.addButton('SomeButton', {
    text: 'My button',
    stateSelector: '.class-of-node' // or use an element (an id would probably work as well, but I haven't tried it myself)
});

或者您可以使用“nodechange”事件使用自定义逻辑
editor.addButton('SomeButton', {
    text: 'My button',
    onPostRender: function() {
        var ctrl = this;

        ed.on('NodeChange', function(e) {
            ctrl.active(e.element.nodeName == 'A');
        });
    }
});

引用:
https://www.tinymce.com/docs/advanced/migration-guide-from-3.x/#controlstates

关于button - TinyMCE 4 切换工具栏按钮状态,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/19878436/

10-12 00:29
查看更多