After some attempts, I came to the conclusion that onclick will not do the job here. After a few hours, I ended up with this solution, which stitches perfectly in Tinymce 4.x:
tinymce.PluginManager.add('my_crazy_plugin', function(editor) { var state; function my_action() { state = !state; editor.fire('mybutton', {state: state}); if (state){ alert(state); } else { alert(state); } } function toggleState_MyButton() { var self = this; editor.on('mybutton', function(e) { self.active(e.state); }); } editor.addCommand('cmd_mybutton', my_action); editor.addButton('mybutton', { image: 'tinymce/plugins/my_crazy_plugin/img/some16x16icon.png', title: 'That Bubble Help text', cmd: 'cmd_mybutton', onPostRender: toggleState_MyButton }); }); tinymce.init({ plugins: [ "my_crazy_plugin" ], toolbar: "mybutton" });
source share