Add a button to the composer tools and change the order of buttons in Tools

Please, help me to add a new button to the composer menu.

I’d like to add a new button to the composer menu. This button will open an external link. I need to add this button to the left side of the composer tools.

I have this code that adds a new button. But I need to change it. The button shouldn’t paste anything in the topic, but open an external link in a new window.

<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>

And another question is how to move the button “upload btn” to the left side (change the current place).

Thank you!

Found a solution. Instead of the current code on the line ‘perform…’ we should place

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

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