Does anyone know if there is an equivalent of TinyMCE 3.5.8 Editor.onEvent (...) in TinyMCE 4.0b1

The plugin I'm trying to connect ( https://github.com/NYTimes/ice ) so that TinyMCE 4 needs access to the key press event BEFORE it is processed by the MCE editor and works with onEvent(...) in 3.5. 8, but it needs to be ported to something more than on('event') in tinymce 4, however there is no obvious alternative.

In tiny MCE 3.5.8 I have

  ed.onEvent.add(function(ed, e) { return changeEditor.handleEvent(e); }); 

But I need something more like

  ed.on('event', function(e) { return changeEditor.handleEvent(e); }); 

However, ed.on('event',...) does not seem to exist in tinymce 4.

He needs to catch the delete key before any other event handler for keystrokes, keystrokes, and keystrokes.

+4
source share
1 answer

Well, after 2 business days trying to get this to work, I realized what the problem is with this particular problem.

For starters, there is no equivalent of onEvent (...) in tinymce 4. However, the plugin does not need access to each event.

If you are going to connect any tinymce plugin that uses the onEvent () method, you will need to determine the events that the plugin is trying to process, and explicitly set an event handler for each of the events that need to be processed:

  ed.on('mousedown', function(e) { return changeEditor.handleEvent(e); }); ed.on('keyup', function(e) { return changeEditor.handleEvent(e); }); ed.on('keydown', function(e) { return changeEditor.handleEvent(e); }); ed.on('keypress', function(e) { return changeEditor.handleEvent(e); }); 

In my case, I needed to not only delegate mousedown, mouseup, keyup, keydown, and keypress events to the plugin, I also had to prevent them from being dismissed prematurely by the / textarea editor:

 ed.on('keydown', function(e) { // prevent the delete key and backspace keys from firing twice if(e.keyCode == 46 || e.keyCode==8) e.preventDefault(); }); 

So keep this in mind if you run into a similar problem.

Oh, and I added the plug of this ICE plugin to my github: https://github.com/catsgotmytongue/ice/

+9
source

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


All Articles