Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

tinymce 4 how to add event handler

In tinymce 3, it seems that we can do this with :

// 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 ?
Need to do it after tinymce initialized.

UPDATE : I tried (still don't work)

tinymce.bind("description", "keyup", function () {
  console.debug('here');
});
like image 870
Hendry H. Avatar asked Nov 05 '13 15:11

Hendry H.


3 Answers

This works :

tinymce.activeEditor.on('keyup', function(e) {
    console.debug("keyup");
});
like image 90
Hendry H. Avatar answered Oct 08 '22 16:10

Hendry H.


Just to follow up on this, if anybody stumbles upon this in future. This in the old 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.

like image 22
Florian Rachor Avatar answered Oct 08 '22 16:10

Florian Rachor


I needed the 'keyup' event to fire. This is how I got it to work:

let editor = tinymce.get("my_textarea_id");
editor.contentDocument.addEventListener('keyup', function (e) { 
   console.debug("keyup");    });
like image 31
Rens Avatar answered Oct 08 '22 17:10

Rens