Can't catch the ForeColor command anymore, tinymce 4.1.4

|▌冷眼眸甩不掉的悲伤 提交于 2019-12-09 21:21:14

问题


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.


回答1:


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!