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&locale=en_GB&version=2" data-macro-name="my-macro" data-macro-parameters="Parameters={"project":["Woods"],"tag":["WHITE128 public"],"fields":["id","Category","Description","Min","Typ","Max","Unit"],"nonparamfields":["id","Category","Type","Description"]}" data-macro-schema-version="1">
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi! May I know what tool you are using to retrieve the macro parameters?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.