我想为我的所有 tinyMCE 组件添加自定义菜单(如文件、编辑)。喜欢做的事here .我尝试使用该代码,但它不起作用,我在想是否有可能以另一种方式进行,无需创建插件,只需在设置时将我的自定义菜单添加到 tinyMCE.init() 函数中。我找到了一种方法来添加这样的子菜单
tinyMCE.init({
mode: "textareas",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste "
],
toolbar: " undo redo | styleselect | bullist numlist outdent indent | link image",
setup: function (ed) {
ed.addMenuItem('example', {
text: 'My menu item',
context: 'tools',
onclick: function () {
ed.insertContent('Hello world!!');
}
});
}
});
这会在“工具”菜单中添加一个菜单项。我需要像上面的链接一样添加整个菜单,而不是那个菜单项,但我不知道如何添加。我尝试像这样在我的设置函数中添加用于创建菜单的代码
tinyMCE.init({
mode: "textareas",
plugins: [
"advlist autolink lists link image charmap print preview anchor",
"searchreplace visualblocks code fullscreen",
"insertdatetime media table contextmenu paste "
],
toolbar: " undo redo | styleselect | bullist numlist outdent indent | link image",
setup: function (ed) {
var c = ed.createMenuButton('mymenubutton', {
title: 'My menu button',
image: 'img/example.gif',
icons: false
});
c.onRenderMenu.add(function (c, m) {
var sub;
m.add({ title: 'Some item 1', onclick: function () {
tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'Some item 1');
}
});
m.add({ title: 'Some item 2', onclick: function () {
tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'Some item 2');
}
});
sub = m.addMenu({ title: 'Some item 3' });
sub.add({ title: 'Some item 3.1', onclick: function () {
tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'Some item 3.1');
}
});
sub.add({ title: 'Some item 3.2', onclick: function () {
tinyMCE.activeEditor.execCommand('mceInsertContent', false, 'Some item 3.2');
}
});
});
}
});
但它不起作用。执行此操作最简单的方法是什么?
最佳答案
设法通过在工具栏中添加一个新菜单来解决它,例如 here
关于javascript - tinyMCE 在运行时添加自定义菜单(带子菜单),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31428045/