Can't catch ForeColor team anymore, tinymce 4.1.4

Tinymce is used to trigger an event to change the color of the text if you fired:

tinymce.activeEditor.on('execCommand', function() {console.log(arguments);} ) 

you will see execCommand ForeColor, which runs whenever the color of the text changes. If you look in the TinyMCE-Textcolor plugin, it doesn't seem to have any execCommands or any way to detect when the text color changes.

+2
source share
1 answer

The TextColor plugin no longer fires the execCommand event, because since it is a commit , it directly uses the Formatter framework . So you cannot get your old event.

However, you can use formatChanged for formatting to provide a callback:

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

JSFiddle demo.

But it also works, even if you just select text that is already colored ... so sad this is not a good alternative.

Of course, formatter.apply can be cleared by the monkey 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}); } 

JSFiddle demo.

But it is impossible to do this on a global scale and repeat for each instance of the tinymce editor so that it is again not the best solution ...

+5
source

All Articles