简体   繁体   English

tinyMCE v6 事件冒泡

[英]tinyMCE v6 event bubbling

I trying to catch keydown triggered on < p > element inside of editor iFrame but with this code, i getting textarea element.我试图捕捉在编辑器 iFrame 内的 < p > 元素上触发的 keydown,但是使用这段代码,我得到了 textarea 元素。 Event.stopPropagation() does not stop bubbling, i still getting topmost element Event.stopPropagation() 不会停止冒泡,我仍然得到最顶层的元素

tinymce.init({
   selector: 'textarea',
   setup:function(editor) {
      editor.on('keydown', function(event) {
         console.log(event.target);
      });
   }
});

I see tinymce.event in API with its own stopPropagation() method but don't get how to make it work.我在 API 中看到tinymce.event有它自己的 stopPropagation() 方法,但不知道如何让它工作。 Tinymce.event return undefined same as editor.event or tinymce.Event.type Tinymce.event 返回 undefined 与 editor.event 或 tinymce.Event.type 相同

also, there is eventDispatcher Utility API but trying to process keydown via eventDispatcher.dispatch() triggered inside of editor.on keydown get me nothing此外,还有eventDispatcher Utility API ,但尝试通过 eventDispatcher.dispatch() 在 editor.on keydown 内部触发来处理 keydown 让我一无所获

In the end, I tried to remove class/style from a block inside of the editor.最后,我尝试从编辑器内的块中删除类/样式。 And cause this block is added programmatically I cant do this with the class name.由于此块是以编程方式添加的,因此我无法使用 class 名称执行此操作。 I need an element pointer where is keydown happened我需要一个 keydown 发生的元素指针

Find out that I can use tinyMCE selection helper to get an element with current focus (which triggered an event) and solve my task发现我可以使用 tinyMCE 选择助手来获取具有当前焦点的元素(触发事件)并解决我的任务

So the final code is所以最后的代码是

tinymce.init({
    selector: 'textarea',
    setup:function(editor) {
       editor.on('keydown', function(event) {
           const element = editor.selection.getNode();
    
           if (editor.dom.hasClass(element, 'classname')) {
    
           }  
       }
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM