经过一番摆弄后,我得出结论,onclick 不会在这里完成这项工作。几个小时后,我最终得到了这个解决方案,它在 Tinymce 4.x 中可以很好地工作:
/* In the timymce > plugins, name your pluginfolder "my_crazy_plugin" and
plugin file as "plugin.min.js" */
/* Your plugin file: plugin.min.js */
tinymce.PluginManager.add('my_crazy_plugin', function(editor) {
var state;
/* Actions to do on button click */
function my_action() {
state = !state; /* Switching state */
editor.fire('mybutton', {state: state});
if (state){
alert(state); /* Do your true-stuff here */
}
else {
alert(state); /* Do your false-stuff here */
}
}
function toggleState_MyButton() {
var self = this;
editor.on('mybutton', function(e) {
self.active(e.state);
});
}
/* Adding the button & command */
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
});
});
/* Your file with the tinymce init section: */
tinymce.init({
plugins: [
"my_crazy_plugin"
],
toolbar: "mybutton"
});