我需要在 TinyMCE 4 中的“工具”项旁边添加另一个下拉菜单:
我找到的最接近的解决方案是:
// Adds a custom menu item to the editor that inserts contents when clicked
// The context option allows you to add the menu item to an existing default menu
tinymce.init({
...
setup: function(ed) {
ed.addMenuItem('example', {
text: 'My menu item',
context: 'tools',
onclick: function() {
ed.insertContent('Hello world!!');
}
});
}
});
但它只是将一个项目添加到已经存在的“工具”菜单中。
最佳答案
当您调用 tinymce.init() 以在现代主题上添加新的菜单栏项目时,您可以尝试同时指定 'menu' 和 'menubar' 选项。
我试过了,它有效。
您可以在 http://fiddle.tinymce.com/39eaab/1 上查看现场演示使用 TinyMCE 4.1.7。
<script type="text/javascript">
tinymce.init({
selector: "textarea",
menu : {
file : {title : 'File' , items : 'newdocument'},
edit : {title : 'Edit' , items : 'undo redo | cut copy paste pastetext | selectall'},
insert : {title : 'Insert', items : 'link media | template hr'},
view : {title : 'View' , items : 'visualaid'},
format : {title : 'Format', items : 'bold italic underline strikethrough superscript subscript | formats | removeformat'},
table : {title : 'Table' , items : 'inserttable tableprops deletetable | cell row column'},
tools : {title : 'Tools' , items : 'spellchecker code'},
newmenu: {title : 'New Menu', items : 'newmenuitem'}
},
menubar: 'file edit newmenu',
setup: function(editor) {
editor.addMenuItem('newmenuitem', {
text: 'New Menu Item',
context: 'newmenu',
onclick: function () { alert('yey!'); }
});
}
});
</script>
<form method="post" action="dump.php">
<textarea name="content"></textarea>
</form>
关于javascript - TinyMCE 4 添加下拉菜单到菜单栏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27060028/