问题
I want to catch the event of some button was pressed. In TinyMCE capture click button event was suggested simple solution of how to do it, but for me it does not work. Could you please help. Here is my code in tinymce/plugins/test folder in editor_plugin_src.js and editor_plugin.js files:
(function(){
tinymce.create("tinymce.plugins.testPlugin",{
init:function(ed,url){
ed.addCommand('my_bold', this.my_bold, this); //calls the function my_bold
ed.onInit.add(function(editor) {
if (editor.controlManager.get('bold')){
editor.controlManager.get('bold').settings.cmd='my_bold_action';
};
});
},
my_bold: function() {
// exectution of regular command
this.editor.execCommand('Bold');
// now do whatever you like here
alert('pressed');
},
createControl:function(b,a){
return null
},
getInfo:function(){
return{
longname:"test plugin",
author:"test author",
authorurl:"http://tinymce.moxiecode.com",
infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example",
version:"1.0"
}
}
});
tinymce.PluginManager.add("test",tinymce.plugins.TestPlugin) })();
Here I activate plugin test:
$(this).tinymce({
...
autoresize_bottom_margin : 15,
mode : 'exact',
elements : clickedId,
theme : 'advanced',
plugins : 'autoresize,test',
force_br_newlines : true,
UPDATE:
(function(){
tinymce.PluginManager.requireLangPack("test");
tinymce.create("tinymce.plugins.test",{
init:function(ed,url){
ed.addCommand('my_bold', this.my_bold, this);//calls the function my_bold
ed.onInit.add(function(editor) {
if (editor.controlManager.get('bold')){
editor.controlManager.get('bold').settings.cmd='my_bold';
}
});
},
my_bold: function() {
// exectution of regular command
this.editor.execCommand('Bold');
// now do whatever you like here
alert('pressed');
},
createControl:function(ed,url){
return null
},
getInfo:function(){
return{
longname:"test plugin",
author:"test author",
authorurl:"http://tinymce.moxiecode.com",
infourl:"http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example",
version:"1.0"
}
}
});
tinymce.PluginManager.add("test",tinymce.plugins.test) })();
Now I have this.
回答1:
Have you added the bold button to your button config? Something like:
theme_advanced_buttons1: "bold,italic,underline";
Update:
editor.controlManager.get('bold').settings.cmd='my_bold_action';
is erroneous, you need:
editor.controlManager.get('bold').settings.cmd='my_bold';
here.
来源:https://stackoverflow.com/questions/11473576/catch-pressing-button-in-plugin-for-tinymce