我正在为新的TinyMCE 4开发一个自定义插件。此插件使用模式屏幕。因为我想使用我已经开发的模态屏幕/JS服务,所以我选择不使用TinyMce的窗口管理器。
问题是TinyMCE在我打开打开模态屏幕时就失去了焦点。我希望TinyMce保持工具栏打开,因为否则我无法与编辑器交互。TinyMCe关闭是因为它接收到模糊事件(很可能是因为它不知道任何打开的窗口)。
显示问题的缩小问题可以在以下Fiddle中找到。单击示例按钮后,问题就会出现。http://fiddle.tinymce.com/pudaab/1
缩短后的代码附在下面:
tinymce.PluginManager.add('example', function(editor, url) {
// Add a button that opens a window
editor.addButton('example', {
text: 'My button',
icon: false,
onclick: function() {
var selection = editor.selection,
dom = editor.dom,
selectedElm,
anchorElm;
// Focus the editor since selection is lost on WebKit in inline mode
editor.focus();
// Open a modal screen using bootstrap
$('#elem').modal();
// Note: As soon as modal opens TinyMce receives a blur event and disables the toolbar
}
});
});
我终于自己解决了这个问题。诀窍是在调用模态屏幕之前先调用editor.nodeChanged()
。然后,当您关闭模式屏幕时,您将调用editor.focus()
。
谢谢你的帮助!