问题描述
Tinymce用于触发文本颜色更改的事件,如果你运行:
Tinymce used to fire an event for the text-color-change, if you ran:
tinymce.activeEditor.on('execCommand', function() {console.log(arguments);} )
你会看到execCommand ForeColor,只要文本颜色发生变化就会运行。如果您查看TinyMCE-Textcolor插件,它似乎没有任何execCommands或任何方法来检测文本颜色何时更改。
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.
推荐答案
TextColor插件不再触发 execCommand
事件,因为以来,它直接使用。因此,您无法获得旧事件。
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.
但是,您可以使用格式化程序上的 formatChanged
来提供回调:
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)
演示。
但是即使你只是选择了一些已经着色的文字,这也会激发......很遗憾,这不是最佳选择。
But this will also fire even if you just select some text which is already colored... so sadly this is not the best alternative.
当然 formatter.apply
可以进行猴子修补以触发旧的 ExecCommand
事件:
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});
}
演示。
但是这不能全局完成,必须重复每个tinymce编辑器实例,所以它再次不是最好的解决方案......
But this cannot be done globally and have to repeated for every tinymce editor instance so it is again not the best solution...
这篇关于无法再捕获ForeColor命令了,请注意4.1.4的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!