嗨,我有一个插件,可以打开一个带有自己的 html 页面的窗口。
tinymce.PluginManager.add('ds_format_edit', function (editor, url) {
editor.addMenuItem('ds_format_edit', {
text: 'Formatvorlage anpassen...',
icon: false,
onclick: function () {
editor.execCommand("ds_format_edit");
}
});
editor.addCommand('ds_format_edit', function () {
editor.windowManager.open({
title: "Formatvorlagen anpassen ...",
url: 'DSFormatEditDialog.html',
width: 800,
height: 350,
buttons: [
{
text: 'OK',
onclick: function () {
top.tinymce.activeEditor.windowManager.close();
}
},
{ text: 'Cancel', onclick: 'cancel' }
]
}, {
tinymce_formats: getFormats(),
});
});
});
tinymce_formats 是我传递给窗口的参数。该对话框修改该参数。一切都有效。 现在,如果窗口已关闭(如果用户按下“确定”按钮),我想重新初始化tinymce编辑器以获取修改后的参数。 有没有开放的回调函数或者其他方式来实现? 谢谢菲利克斯
编辑: 我用一个按钮来调用这个插件。该插件打开一个带有参数的窗口。在这个窗口中我做了一些事情并修改了参数。如果窗口已关闭,我想使用重新初始化功能。我需要一个知道窗口何时关闭的函数来执行重新初始化函数。
最佳答案
要重置所有内容(按钮状态和内容),您需要卸载编辑器并像这样再次初始化它:
# Remove TinyMCE instance
tinyMCE.remove();
# Initialize TinyMCE again
tinyMCE.init({ ... });
或者,如果您只需要清空文本内容,请使用:
tinyMCE.get('#my-textarea-id').setContent("");
要告诉您的主应用程序窗口已关闭,您可以触发自定义事件:
{
text:'OK',
onclick: function () {
jQuery(document).trigger('myCustomCloseEvent');
top.tinymce.activeEditor.windowManager.close();
}
}
在您的主应用程序中,绑定(bind)事件:
jQuery(document).on("myCustomCloseEvent", function()
{
alert('Window has been closed');
});
关于javascript - 微小的 : How can I check if a window has been closed?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25563467/