How to retrieve macro parameters of Confluence?

AustinS November 20, 2017

I've created a user macro for Confluence and I was trying to retrieve macro parameters by using attribution "data-macro-parameters" to re-edit this macro and update parameters of this macro.  

Now I can retrieved correct parameters when there is only one macro on the Confluence page, BUT if added multiple same ,macros on the same page, then re-edit any of macro except the first one, I always get the first's parameters, that because these macro all has attribution "data-macro-parameters".   How could identify which macro user wants to edit?

Any help could greatly appreciated.

These macros have similar html code:

<img class="editor-inline-macro" src="/confluence/plugins/servlet/confluence/placeholder/macro?definition=e3Jtc3ZpZXdlci1tYWNybzpQYXJhbWV0ZXJzPXsicHJvamVjdCI6WyJXSElURSJdLCJ0YWciOlsiV0hJVEUxMjggcHVibGljIl0sImZpZWxkcyI6WyJpZCIsIkNhdGVnb3J5IiwiRGVzY3JpcHRpb24iLCJNaW4iLCJUeXAiLCJNYXgiLCJVbml0Il0sIm5vbnBhcmFtZmllbGRzIjpbImlkIiwiQ2F0ZWdvcnkiLCJUeXBlIiwiRGVzY3JpcHRpb24iXX19&amp;locale=en_GB&amp;version=2" data-macro-name="my-macro" data-macro-parameters="Parameters={&quot;project&quot;:[&quot;Woods&quot;],&quot;tag&quot;:[&quot;WHITE128 public&quot;],&quot;fields&quot;:[&quot;id&quot;,&quot;Category&quot;,&quot;Description&quot;,&quot;Min&quot;,&quot;Typ&quot;,&quot;Max&quot;,&quot;Unit&quot;],&quot;nonparamfields&quot;:[&quot;id&quot;,&quot;Category&quot;,&quot;Type&quot;,&quot;Description&quot;]}" data-macro-schema-version="1">

 

2 answers

0 votes
James Richards
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 22, 2017

Hi AustinS,

Confluence has jQuery built in, so you can iterate over the html elements you want with something like

AJS.$('img.editor-inline-macro').each(function(index) { console.log( index + ": " + $( this ).text() ); });

You can see more about the each() function in the jquery docs here

You may find if you enter that JavaScript into tinymce then it will strip out the code, so better to put it into a HTML macro block.

James.

 

AustinS November 22, 2017

Thanks James, but what I need is when user randomly click to edit the one macro of this page, can retrieve the parameters of this one, not the first one's. 

We do not need to iterate to get each of them, just want to identify which macro is user 'click to edit'.  Because for each <img>, there is no 'id' attribution to identify them. Any idea ?

Thanks again.

S

James Richards
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 22, 2017

Ah, so you mean when the editor is being used you want to get the one that is selected?

Hmmm, that's pretty tricky because you need to insert a click listened in to the DOM and wait for events.

Something like this would do the trick

AJS.$('img.editor-inline-macro').on('click', function() { alert('yes!'); });

See

But it doesn't look like the AJS object is defined when using the editor for the editor items.

I'd suggest asking over in the developer community at

 

James.

AustinS November 22, 2017

Thanks for your replies, James.

Will do that.

Happy Thanksgiving!

S

0 votes
AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 21, 2017

Hi! May I know what tool you are using to retrieve the macro parameters? 

AustinS November 21, 2017

Im using Tinymce as editor. And using JavaScript to getting parameters.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events