Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

Equivalent for AJS.MacroBrowser.setMacroJsOverride when inserting macro with markup?

RikuK September 23, 2014

Hello,

I have successfully implemented custom dialog that opens when macro is selected from the Macro browser. I did it with AJS.MacroBrowser.setMacroJsOverride. Now i need to get that same function invoked, that i now have activated with AJS.MacroBrowser.setMacroJsOverride also when i insert macro with \{my-macro} markup. Is it possible to hook on that, with same way as you can hook on macro browser?

 

EDIT: More info

So, i feel like this should be supported and i just can't find the right hooks. Right now i can insert new macro from macro browser. My macro uses custom dialog to setup the macro. I need to be able to insert macro with normal markup in edit mode. I just can't find a way to open that dialog to correctly populate macro with initial data. This data comes from the user and thus can't be written to plugin code.

7 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Steffen Prendke July 21, 2015

Hello Riku, did you solve your Problem in the meantime. I am also have the problem. My macro is inserted directly, without my dialog is shown before.

0 votes
Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2014

For those too busy to read all the comments above, here's a summary. The "opener" should work both when inserting through the Macro Browser and through wikimarkup. The right way of using setMacroJsOverride is:

  • Trigger the code with the event "init.rte"
AJS.bind("init.rte", function() {
    AJS.MacroBrowser.setMacroJsOverride('my-macro', {
        opener: function (macro) {
            // This instruction is mandatory. If you miss it, the next macro won't insert.
            tinymce.confluence.macrobrowser.macroBrowserComplete({name: "my-macro", "bodyHtml": undefined, "params": {}});
        }
    });
  • And attach this resource to the "editor" context:
<web-resource name="JS / CSS for the macro in the Rich Text Editor" key="my-plugin-rte">
        <transformation extension="js">
            <transformer key="jsI18n"/>
        </transformation>
        <resource type="download" name="my-plugin-code-for-the-rte.js" location="js/my-plugin-code-for-the-rte.js" />
        <context>editor</context>
    </web-resource>

I hope it will work with this code.

RikuK October 1, 2014

Thanks. I will try this.

J D
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2014

Hi @Riku Koskinen , Did you make it work? regards

RikuK November 27, 2014

Nope, problem still exist. Works fine from macro browser, but {my-macro} does not open the dialog

RikuK November 27, 2014

Sorry for double comment. We will test this again soonish. We have to get it to work, but there is so many things that can break this ( as we are playing with requirejs and tens of other libraries ). I will post here, when were are either out of bullets or found out the problem.

J D
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 27, 2014

Okay thanks.

Boris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
January 18, 2015

I tried the solution above and the problem remains for me. Custom macro editor is not triggered when typing macro name in page editor.

Nick Bremer October 8, 2015

Add a required parameter in atlassian-plugin.xml like so: <parameter name="somename" type="string" required="true"> This forces Confluence to call your own opener function.

Boris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2015

@Nick Bremer Is this documented somewhere?

Boris
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 8, 2015

I can confirm that Nick Bremer's solution works.

Nick Bremer October 27, 2015

@Boris Jockov [draw.io] Let me try to find that reference.

0 votes
Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2014

Yup totally: - init.rte is triggered after the editor loads. If your code is triggered before, setMacroJsOverride may not exist or may exist and not do anything; - The editor is loaded in background while a page is viewed. So when you click Edit, Confluence replaces a layer with another and changes the URL to make you believe you've changed page. They did it to accelerate the loading of the editor. So when you switch from a View page to an Edit page, you script may not be triggered at the right time. The only way to ensure the script is loaded at the right time is to use the "editor" context and the "init.rte" event.

0 votes
RikuK October 1, 2014

Hi, i have "AJS.bind("init.rte", function())" but its commented out :) I have to find out who did it and why. Could that be the reason?

0 votes
Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 1, 2014

I'm the editor of Requirement Yogi. When people type {, then drop-down appears with the list of macros, then when they type "req", the Requirement Yogi macro gets selected. At that point, the "opener" is called. Something else may be broken in this path, so I'll give you a few ideas to debug: - Make sure you have no red error message in Chrome's console, and make sure you hard-refresh (Command+Shift+R or Shift+F5), - If your testing method is always "Refresh the page, insert the macro with the Macro Browser, check it works, then use the {my... syntax, check it doesn't work", then try doing the opposite, like using the "{" syntax before trying the Macro browser, - Are you sure you've included your javascript in the right context? In atlassian-plugin.xml, it should use <context>editor</context> - Are you sure you've bound the execution to the "init.rte" event? - Let's check we have the same syntax: AJS.bind("init.rte", function() { AJS.MacroBrowser.setMacroJsOverride('requirement', { opener: function (macro) { // This instruction is mandatory. If you miss it, the next macro won't insert. tinymce.confluence.macrobrowser.macroBrowserComplete({name: "requirement", "bodyHtml": undefined, "params": {}}); } }); Once again, sorry if you've already tried all of this.

0 votes
RikuK October 1, 2014

Yes, i would like to use {my-macro} syntax right in the editor. Currently it opens dialog from macro browser but not when using that kind of syntax. But you are saying it should open? Definitely not using wikimarkup dialog and no need for that.

0 votes
Adrien Ragot 2
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
September 30, 2014

Do you type {my-macro} in the editor itself or in the Wikimarkup dialog? If you do it straight in the editor, then the dialog should display (if it is declared as an "opener" in setMacroJsOverride). If you do it in the wikimarkup dialog, and you expect your dialog to display after the content is inserted, then I don't think there would be a way of doing it.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS
AUG Leaders

Atlassian Community Events