【问题标题】:Does anyone know if there's an equivalent of TinyMCE 3.5.8 Editor.onEvent(...) is in TinyMCE 4.0b1有谁知道 TinyMCE 3.5.8 Editor.onEvent(...) 是否在 TinyMCE 4.0b1 中
【发布时间】:2013-06-28 17:07:02
【问题描述】:

我正在尝试将 (https://github.com/NYTimes/ice) 移植到 TinyMCE 4 的插件需要在 MCE 编辑器处理它之前访问按键事件并在 3.5.8 中与 onEvent(...) 一起使用,但需要迁移类似于 tinymce 4 中的 on('event'),但是没有明显的替代方案。

在微型 MCE 3.5.8 中我有

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

但我需要更多类似的东西

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

但是,tinymce 4 中似乎不存在 ed.on('event',...)

它需要能够在 keydown、keyup 和 keypress 的任何其他事件处理程序之前捕获删除键。

【问题讨论】:

    标签: tinymce tinymce-4


    【解决方案1】:

    好的,经过 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);
                    });
    

    就我而言,我不仅需要将 mousedown、mouseup、keyup、keydown 和 keypress 事件委托给插件,还必须防止它们被编辑器/文本区域过早触发:

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

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

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2018-01-16
      • 2015-05-06
      • 2013-10-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-08-16
      • 2011-01-26
      相关资源
      最近更新 更多