TinyMCE 4 toggle toolbar button state

后端 未结 4 1375
轻奢々
轻奢々 2021-01-03 08:39

What is the simplest way to toggle the state of a toolbar button (like it works with the default bold-button)? I can\'t \"get\" to that class i Tinymce that changes the butt

4条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-03 09:33

    In TinyMCE 4 you can use the simpler stateSelector setting:

    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)
    });
    

    Or you can use custom logic using the "nodechange" event

    editor.addButton('SomeButton', {
        text: 'My button',
        onPostRender: function() {
            var ctrl = this;
    
            ed.on('NodeChange', function(e) {
                ctrl.active(e.element.nodeName == 'A');
            });
        }
    });
    

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

提交回复
热议问题