TinyMCE 捕获点击按钮事件 [英] TinyMCE capture click button event
问题描述
在 TinyMCE 中是否可以知道点击了哪个按钮?所以我可以对特定按钮的特定事件进行特定操作.
is it possible in TinyMCE to know which button was clicked? so I could place specific action on specific event of a specific button.
这里的按钮是默认的控制按钮,如粗体/斜体/选择字体,而不是自定义按钮.
the buttons here are default control-buttons like bold/italic/select-font not a custom button one.
可能在 init 中,但我不知道该调用什么.我可以捕获编辑器的事件,但不能捕获按钮的事件.
probably in the init, but I have no idea what to call. I could capture the editor's events but not the button's.
例如,假设我希望每次单击粗体按钮时都弹出一个消息框.如何捕获粗体按钮的点击事件?创建自定义按钮是唯一的方法吗?
For example, let's say I want a messagebox popped-up everytime bold button is clicked. How to capture the click event of bold button? is creating custom button the only way?
推荐答案
不,您可以定义自己的命令并在 buttonklick 上调用此命令(+ 默认操作).我不知道您是否想要所有按钮的通用方式.但是只用一两个按钮就很容易做到.
No, you can define an own command and call this command (+ the defualt action) on buttonklick. I do not know if you want a generic way for all buttons. But it is easy to do it just for one or two buttons.
示例:我们想在粗体按钮上放置一个操作.首先,我们在我们自己的插件中定义一个自己的命令(在init : function(ed, url)"部分):
Example: We want to put an action on the bold button. First we define an own command in one of our own plugins (in the "init : function(ed, url)" -section):
ed.addCommand('my_bold', this.my_bold, this); //calls the function my_bold
然后我们用命令覆盖默认操作:
Then we overwrite the default action with an the command:
if (ed.controlManager.get('bold')){
ed.controlManager.get('bold').settings.cmd='my_bold_action';
};
现在,我们只需要定义函数 my bold
Now, we only need to define the function my bold
my_bold: function() {
// exectution of regular command
this.editor.execCommand('Bold');
// now do whatever you like here
...
},
这篇关于TinyMCE 捕获点击按钮事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!