tinymce.PluginManager.add('editor135', function (editor, url) { let activeEditor = null; // 用于保存当前活动的 tinymce 编辑器实例 let iframeSrc = '' const openDialog = function (editor) { // iframeSrc = 'https://www.135editor.com/simple_editor.html?callback=true&appkey=' + '&editorId=' + editor.id; // 无免费样式过滤操作 iframeSrc = 'https://www.135editor.com/beautify_editor.html?callback=true&appkey=' + '&editorId=' + editor.id; // 有免费样式过滤操作 activeEditor = editor; // return window.open(iframeSrc, '_blank'); // 需要注释这行,注释后可避免原有文章内容无法同步的问题 return editor.windowManager.openUrl({ title: '135编辑器', url: iframeSrc, size: 'large', }); }; // 接收135传来的数据 window.addEventListener('message', function (event) { if (event.origin !== 'https://www.135editor.com') { return false; } if (typeof event.data !== 'string') { if (event.data.ready) { console.log('135加载完成'); // 获取135实例 const editor135 = document.querySelector(`iframe[src='${iframeSrc}']`); if (editor135) { editor135.contentWindow.postMessage(editor.getContent(), '*'); } } return; }; if (activeEditor) { // 使用 activeEditor 变量来访问当前活动的 tinymce 编辑器实例 activeEditor.setContent(event.data); activeEditor.windowManager.close(); activeEditor = null; // 重置 activeEditor 变量以防止后续的错误处理 } }, false); editor.ui.registry.getAll().icons.editor135 || editor.ui.registry.addIcon('editor135', '' ); // 注册一个工具栏按钮名称 editor.ui.registry.addButton('editor135', { // text: '135', icon: 'editor135', tooltip: '使用135编辑器', onAction: function () { openDialog(editor); } }); // 注册一个菜单项名称 menu/menubar editor.ui.registry.addMenuItem('editor135', { text: '135编辑器', icon: 'editor135', onAction: function () { openDialog(editor); } }); return { getMetadata: function () { return { // 插件名和链接会显示在“帮助”→“插件”→“已安装的插件”中 name: "135编辑器", //插件名称 url: "https://marketplace.plugins-world.cn", //作者网址 }; } }; });