Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Deleted user
0 / 0 points
Next:
badges earned

Your Points Tracker
Challenges
Leaderboard
  • Global
  • Feed

Badge for your thoughts?

You're enrolled in our new beta rewards program. Join our group to get the inside scoop and share your feedback.

Join group
Recognition
Give the gift of kudos
You have 0 kudos available to give
Who do you want to recognize?
Why do you want to recognize them?
Kudos
Great job appreciating your peers!
Check back soon to give more kudos.

Past Kudos Given
No kudos given
You haven't given any kudos yet. Share the love above and you'll see it here.

It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

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

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

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.

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.

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.

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?

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.

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:
&lt;web-resource name="JS / CSS for the macro in the Rich Text Editor" key="my-plugin-rte"&gt;
        &lt;transformation extension="js"&gt;
            &lt;transformer key="jsI18n"/&gt;
        &lt;/transformation&gt;
        &lt;resource type="download" name="my-plugin-code-for-the-rte.js" location="js/my-plugin-code-for-the-rte.js" /&gt;
        &lt;context&gt;editor&lt;/context&gt;
    &lt;/web-resource&gt;

I hope it will work with this code.

Thanks. I will try this.

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

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

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.

Okay thanks.

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

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.

@Nick Bremer Is this documented somewhere?

I can confirm that Nick Bremer's solution works.

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

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.

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

TAGS

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you