有没有人知道是否有相当于TinyMCE 3.5.8 Editor.onEvent(...)在TinyMCE 4.0b1

Cur*_*lin 4 tinymce tinymce-4

我试图移植(https://github.com/NYTimes/ice)到TinyMCE 4 的插件需要访问一个按键事件,然后由MCE编辑器处理并onEvent(...)在3.5.8中使用但需要被迁移到更像on('event')是tinymce 4的东西,但是没有明显的选择.

在微小的MCE 3.5.8中,我有

            ed.onEvent.add(function(ed, e) {
                return changeEditor.handleEvent(e);
            });
Run Code Online (Sandbox Code Playgroud)

但我需要更像的东西

                ed.on('event', function(e) {
                    return changeEditor.handleEvent(e);
                });
Run Code Online (Sandbox Code Playgroud)

然而,ed.on('event',...)似乎并不存在于tinymce 4中.

它需要能够在keydown,keyup和keypress的任何其他事件处理程序之前捕获delete键.

Cur*_*lin 9

好的,经过2个工作日试图让这个工作,我发现了这个特定问题的问题.

对于初学者来说,在tinymce 4中没有与onEvent(...)等效的东西.但是插件无论如何都不需要访问每个事件.

如果您要移植任何使用onEvent()方法的tinymce插件,那么您将需要识别插件尝试处理的事件,并为每个需要处理的事件显式设置事件处理程序:

                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);
                });
Run Code Online (Sandbox Code Playgroud)

在我的情况下,我不仅需要将mousedown,mouseup,keyup,keydown和keypress事件委托给插件我还必须防止它们被编辑器/ textarea过早地触发:

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

因此,如果遇到类似的问题,请记住这一点.

哦,我在我的github上添加了这个ICE插件的一个分支:https://github.com/catsgotmytongue/ice/