简体   繁体   English

tinymce 4 如何添加事件处理程序

[英]tinymce 4 how to add event handler

In tinymce 3, it seems that we can do this with :在 tinymce 3 中,我们似乎可以通过以下方式做到这一点:

// Adds a click handler to the current document
tinymce.dom.Event.add(document, 'click', function(e) {
   console.debug(e.target);
});

What is the syntax in tinymce 4 ? tinymce 4 中的语法是什么?
Need to do it after tinymce initialized.需要在 tinymce 初始化后做。

UPDATE : I tried (still don't work)更新:我试过了(还是不行)

tinymce.bind("description", "keyup", function () {
  console.debug('here');
});

This works :这有效:

tinymce.activeEditor.on('keyup', function(e) {
    console.debug("keyup");
});

Just to follow up on this, if anybody stumbles upon this in future.只是为了跟进这一点,如果将来有人偶然发现这一点。 This in the old API:这在旧 API 中:

tinymce.dom.Event.add(document, 'click', function(e) {
 console.debug(e.target);
});

Would now be correctly:现在应该是正确的:

tinymce.DOM.bind(document, 'click', function(e) {
 console.debug(e.target);
});

So if you are getting the "undefined is not a function" error on .add this should solve your problem.因此,如果您在 .add 上收到“未定义不是函数”错误,这应该可以解决您的问题。

I needed the 'keyup' event to fire.我需要触发 'keyup' 事件。 This is how I got it to work:这就是我让它工作的方式:

editor.contentDocument.addEventListener('keyup', function (e) { console.debug("keyup"); });

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

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