使用 tinyMCE 时,有没有办法从编辑器的实例中获取对工具栏的引用

When using tinyMCE, is there a way to get a reference to the toolbar from an editor's instance?

本文关键字:实例 获取 引用 工具栏 编辑器 tinyMCE 有没有 使用      更新时间:2023-09-26

我正在使用tinymce,内联模式,在某些情况下,我需要能够使用javascript显示/隐藏活动编辑器的工具栏。它应该是这样的:

tinymce.activeEditor.getToolbar() // getToolbar doesn't exist

只是给定一个编辑器实例,我找不到任何方法来获取对其工具栏的引用。

另请注意,页面上可能有多个工具栏,但在任何给定时间只显示一个工具栏。

工具栏初始化如下:

     tinymce.init({
                selector: "#" + id,
                menubar: false,
                inline: true,
                theme: "modern",
                oninit: "setPlainText"
                ...

谢谢。

在TinyMCE论坛上有关于这个问题的讨论。它建议:

...
    setup: function (theEditor) {
        theEditor.on('focus', function () {
            $(this.contentAreaContainer.parentElement).find("div.mce-toolbar-grp").show();
        });
        theEditor.on('blur', function () {
            $(this.contentAreaContainer.parentElement).find("div.mce-toolbar-grp").hide();
        });
        theEditor.on("init", function() {
            $(this.contentAreaContainer.parentElement).find("div.mce-toolbar-grp").hide();
        });
    }
...