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.
Community moderators have prevented the ability to post new answers.
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.
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:
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": {}}); } });
<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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Riku Koskinen , Did you make it work? regards
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Okay thanks.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I tried the solution above and the problem remains for me. Custom macro editor is not triggered when typing macro name in page editor.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@Nick Bremer Is this documented somewhere?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
I can confirm that Nick Bremer's solution works.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Community moderators have prevented the ability to post new answers.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.