在工具栏中添加一个按钮到编辑器工具,并更改工具中按钮的顺序

请帮我向编辑器菜单添加一个新按钮。

我想在编辑器菜单中添加一个新按钮。此按钮将打开一个外部链接。我需要将此按钮添加到编辑器工具的左侧。

我有这段代码可以添加一个新按钮。但我需要更改它。该按钮不应在主题中粘贴任何内容,而应在新窗口中打开外部链接。

<script type="text/discourse-plugin" version="0.8">
const user = api.getCurrentUser();
const groups = ['group1', 'group2'];
const hasGroup = user.groups.some(({name}) => groups.indexOf(name) !== -1);
if (user.staff || hasGroup) {
  api.onToolbarCreate(toolbar => {
    toolbar.addButton({
        id: "times-circle",
        group: "fontStyles",
        title: "Title",  
        icon: "times-circle",
        perform: e => e.applySurround("del", "/del", "Title")
    });
  });
}
</script>

另一个问题是如何将“上传按钮”移动到左侧(更改当前位置)。

谢谢!

找到了一个解决方案。将当前代码的 ‘perform…’ 行替换为:

	perform: function openInNewTab(url) {
                 window.open('https://google.com', '_blank').focus();
                }
1 个赞

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.