TinyMCE Button Press Event

Is it possible in TinyMCE to find out which button was pressed? so I can post specific actions for a specific event of a particular button.

the buttons here are the default control buttons, for example, bold / italics / select-font, and not a custom button.

perhaps in init, but I have no idea what to call. I could capture the events of the editor, but not the buttons.

For example, let's say I want the pop-up button to be pressed for each time. How to capture click event in bold? creates a custom button in only a way?

+4
source share
2 answers

No, you can define your own command and call this command (+ defualt action) on buttonklick. I don’t know if you need a common way for all buttons. But this is easy to do for just one or two buttons.

Example: We want to add an action to a bold button. First, we define our own command in one of our own plugins (in the section "init: function (ed, url)":

ed.addCommand('my_bold', this.my_bold, this); //calls the function my_bold 

Then we overwrite the default action with the command:

 if (ed.controlManager.get('bold')){ ed.controlManager.get('bold').settings.cmd='my_bold_action'; }; 

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 ... }, 
+4
source

ed.controlManager must be called in the onInit method:

 ed.onInit.add(function(editor) { ....... ........ if (editor.controlManager.get('bold')){ editor.controlManager.get('bold').settings.cmd='my_bold_action'; }; }); 
+1
source

Source: https://habr.com/ru/post/1400968/


All Articles