删除TinyMCE 4中的子菜单项

问题描述 投票:0回答:2

我正在尝试从 WordPress 中的 TinyMCE 下拉工具栏按钮中删除子项目。

该按钮是一个插件按钮(TinyMCE Table Button),它插入一个允许用户在表格上进行 CSS 样式设置的项目。

TinyMCE plugin generated dropdown

(Taulukon ominaisuudet == 表属性)

工具栏按钮是用

创建的
editor.addButton("table", {
    type: "menubutton",
    title: "Table",
    menu: menuItems
});

菜单项是用

创建的
editor.addMenuItem('tableprops', {
    text: 'Table properties',
    context: 'table',
    onPostRender: postRender,
    onclick: dialogs.tableProps
});

editor
是TinyMCE插件构造函数参数:

define("tinymce/tableplugin/Plugin", [
    "tinymce/tableplugin/TableGrid",
    ...
    "tinymce/PluginManager"
], function(TableGrid, Quirks, CellSelection, Dialogs, Tools, TreeWalker, Env, PluginManager) {
    var each = Tools.each;

    function Plugin(editor) {
        var clipboardRows, self = this, dialogs = new Dialogs(editor);

        ...

编辑器有

addMenuItem
的功能,但我找不到类似
removeMenuItem
的功能。我还尝试在编辑器中找到菜单项,以便我可以手动将其删除,但系统对于按钮和菜单的位置有点阴暗。

是否有一种逻辑方法可以在 TinyMCE 中删除菜单项,或者在生成编辑器后我必须直接从 DOM 中删除它吗?

javascript wordpress button menu tinymce
2个回答
3
投票

更新:请意识到,您正在使用不同的表插件。 我想一个简单的方法是检查元素/源并获取该菜单项的元素 ID 并使用 CSS 隐藏它。

<style>
#mceu_38 {display:none !important;}
</style>

以下是我的原始回复,用于编辑默认菜单栏


可以在init函数中自定义菜单栏:

tinymce.init({
    selector: "textarea",
    menu : { // this is the complete default configuration
        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 deletetable | cell row column'},
        tools  : {title : 'Tools' , items : 'spellchecker code'}
    },    
    plugins: [
        "advlist autolink lists link image charmap print preview anchor",
        "searchreplace visualblocks code fullscreen",
        "insertdatetime media table contextmenu paste"
    ],
    toolbar: "insertfile undo redo | styleselect | bold italic | alignleft aligncenter alignright alignjustify | bullist numlist outdent indent | link image"
});

只需删除每个菜单属性中不需要的项目即可。

这是删除表属性的示例: http://fiddle.tinymce.com/43eaab

这是文档:http://www.tinymce.com/wiki.php/Configuration:menu

gl。


0
投票

这是对我有用的一种方法

const buttons = editor.ui.registry.getAll().menuItems

    for(const button in buttons) {
        if(button === 'tableprops' || button === 'tablecellprops' || button === 'tablerowprops')
        delete buttons[button]
    }

这可以放在

init_instance_callback

我在这里使用 TinyMCE 进行 React,不确定它是否与其他人相同的 init 函数名称。

© www.soinside.com 2019 - 2024. All rights reserved.