我正在尝试在 Elementor 文本小部件工具栏中添加一个自定义按钮,旁边是其他按钮(如粗体、斜体、下划线等)。似乎使用 PHP 自定义实例的功能可能被禁用,但这是可能的使用 JavaScript 代替。
我可以使用以下代码取回视图,但无法取回编辑器实例。
elementor.hooks.addAction( 'panel/open_editor/widget/text-editor', function( panel, model, view ) {}
我尝试了以下建议,但之后似乎没有返回任何内容。
// get active instances of the editor
let editor = tinymce.activeEditor;
var editor = elementor.editors.get(0).getEditModel().get('editor');
var activeEditor = view.getOption('editor');
获取编辑器实例后建议的其余代码如下,但我还没有做到这一点。
// add a button to the editor buttons
editor.addButton('tooltip', {
text: 'tooltip',
icon: false,
onclick: (editor) => {
tooltipCallback(editor);
}
});
// the button now becomes
let button=editor.buttons['tooltip'];
// find the buttongroup in the toolbar found in the panel of the theme
let bg=editor.theme.panel.find('toolbar buttongroup')[0];
// without this, the buttons look weird after that
bg._lastRepaintRect=bg._layoutRect;
// append the button to the group
bg.append(button);
你尝试过吗:
var editor = top.window.tinymce.activeEditor
可能会有帮助。