Can't catch the ForeColor command anymore, tinymce 4.1.4 Can't catch the ForeColor command anymore, tinymce 4.1.4 wordpress wordpress

Can't catch the ForeColor command anymore, tinymce 4.1.4


The TextColor plugin no longer fires the execCommand event because since this commit it directly uses the Formatter infrastructure. So you cannot get your old event.

However you can use the formatChanged on the formatter to provide a callback:

tinymce.activeEditor.formatter.formatChanged('forecolor', function (isNew, args) {    if (isNew)    console.log("new color", args.node.style.color);}, true)

Demo JSFiddle.

But this will also fire even if you just select some text which is already colored... so sadly this is not the best alternative.

Of course the formatter.apply can be monkey-patched to fire the old ExecCommand event:

var oldApply = tinymce.activeEditor.formatter.apply;tinymce.activeEditor.formatter.apply = function apply(name, vars, node) {    oldApply(name, vars, node);    tinymce.activeEditor.fire('ExecCommand', {name: name, vars: vars});}

Demo JSFiddle.

But this cannot be done globally and have to repeated for every tinymce editor instance so it is again not the best solution...