Tinymce used to fire an event for the text-color-change, if you ran:
tinymce.activeEditor.on('execCommand', function() {console.log(arguments);} )
you would see the execCommand ForeColor, ran whenever the text color is changed. If you look in TinyMCE-Textcolor plugin, it doesn't seem to have any execCommands or any way to detect when text-color changes.
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...
来源:https://stackoverflow.com/questions/27540258/cant-catch-the-forecolor-command-anymore-tinymce-4-1-4