我试图在TinyMCE中创建一个简单的测试插件。首先,文档中似乎没有一个页面来详细说明如何做到这一点。
我找到了此页 for v4,这是过时的谷歌搜索,虽然它据称是在“高级主题”下,没有链接到这个页面!但是,它会引发我可以使用的异常。它告诉我我需要改变“编辑”转到“editor.ui.register”。这使异常消失,但我的工具栏和菜单项没有出现在任何地方!
我试着在页面上切换到v5,然后搜索并找到这个例子。再次,它引导我到一个页面,没有链接到它在适当的领域。
我尝试了示例代码“原样”,并在没有"ui.registry“的情况下获得了关于过时用法的相同异常!但是我修正了它,然后得到了这个例外:
Uncaught Error: Errors:
Failed path: (toolbarbutton)
Could not find valid *strict* value for "onAction" in {
"type": "button",
"text": "My button",
"icon": false
},Failed path: (toolbarbutton > icon)
Expected type: string but got: boolean
Input object: {
"type": "button",
"text": "My button",
"icon": false
}
at theme.min.js:9
at Object.getOrDie (theme.min.js:9)
at theme.min.js:9
at theme.min.js:9
at Object.fold (theme.min.js:9)
at theme.min.js:9
at Object.fold (theme.min.js:9)
at dE (theme.min.js:9)
at theme.min.js:9
at _ (theme.min.js:9)我又玩了几次,但没有成功。例如,如果我删除按钮,工具栏根本不会出现,但没有错误。如果删除工具栏引用,工具栏将重新出现,但菜单选项仍然不会出现。
我所要做的就是创建一个简单的示例,在其中我创建一个菜单选项,将一些东西记录到控制台,并向工具栏添加一个按钮,该按钮在单击时也会这样做。
我该怎么做?我发现的所有其他问题似乎都是指较早版本的TinyMCE。
发布于 2019-03-29 04:09:55
该页面实际上已从导航中删除,因为它还没有为TinyMCE 5.0进行更新,但它实际上是在今天进行了更新,以包含一个适用于5.0的示例。我猜您可能已经访问了页面的缓存副本,所以我也会在这里添加详细信息。
菜单和按钮API在5.0中发生了相当大的变化,因此可以在这里找到用于注册菜单和按钮的新文档:
因此,要在自定义插件中使用它们,您可以这样做:
tinymce.PluginManager.add('example', function(editor, url) {
var openDialog = function () {
return editor.windowManager.open({
title: 'Example plugin',
body: {
type: 'panel',
items: [
{
type: 'input',
name: 'title',
label: 'Title'
}
]
},
buttons: [
{
type: 'cancel',
text: 'Close'
},
{
type: 'submit',
text: 'Save',
primary: true
}
],
onSubmit: function (api) {
var data = api.getData();
// Insert content when the window form is submitted
editor.insertContent('Title: ' + data.title);
api.close();
}
});
};
// Add a button that opens a window
editor.ui.registry.addButton('example', {
text: 'My button',
onAction: function () {
// Open window
openDialog();
}
});
// Adds a menu item, which can then be included in any menu via the menu/menubar configuration
editor.ui.registry.addMenuItem('example', {
text: 'Example plugin',
onAction: function() {
// Open window
openDialog();
}
});
return {
getMetadata: function () {
return {
name: "Example plugin",
url: "http://exampleplugindocsurl.com"
};
}
};
});要将菜单添加到菜单中,还必须包括一个menu和menubar配置,因为上下文属性已经被删除。不过,我们正在寻找其他方法将其带回(请参阅https://github.com/tinymce/tinymce/issues/4835)。
这里有一个小提琴,显示这一切都在工作:http://fiddle.tinymce.com/VEgaab
https://stackoverflow.com/questions/55409086
复制相似问题