Documentation for AJS.MacroBrowser.setMacroJsOverride

Is there a documentation for AJS.MacroBrowser.setMacroJsOverride? I want to create a custom dialog for my macro plugin.

Hi @ChongJingHong ,
We don’t have official public documentation for MacroJsOverrides as far as I’m aware. However I’m more than happy to answer any questions about specific override functionality.

If you want to create an entirely custom dialog, you will have to override the opener function.

If the opener override is present, the macro browser will call the custom opener function rather than the default. You will then have to do all the work of rendering an AUI dialog containing the content of the macro editor, including all of the parameter inputs fields, a save button and ideally a previewer. Then once the user clicks the save button, you can call tinymce.confluence.macrobrowser.macroBrowserComplete with an object containing the macro parameter data to be stored on the page.

E.g.

AJS.toInit(function () {
    AJS.MacroBrowser.setMacroJsOverride('macroName', { opener: function (macro) {
        // add dialog2 to DOM and show dialog
       submitButton.addEventListener('click', function(e) {
            // Collect all user inputted macro data
            tinymce.confluence.macrobrowser.macroBrowserComplete({name: 'macroName', params: macroData})
       });
   });
});

If you don’t need to override the entire macro editor dialog, a subset of the other supported macro overrides are:

Customise macro input fields

  • field override to customise the specific field input elements

Callbacks to modify the raw macro data input by the user:

  • manipulateMarkup - called once the macro editor form submit has been clicked. Called with the entire macro editor metadata including the parameters before the parameters are extracted from the form.
  • beforeParamsRetrieved - called after manipulateMarkup with the final macro parameters right before macroBrowserComplete is called.

Callback when previewing the macro:

  • postPreview - called with the preview iframe element and macro metadata when the user previews the macro

We also have callbacks for when an existing macro is being edited

  • updateSelectedMacro - called with the macro object
  • getMacroDetailsFromSelectedMacro - called with the macro metadata

@aknight Omg thank you so much for taking the time to write these information down.

If I want a parameter to be able to input multiple lines, I could just use the field override to change the input to a <textarea>?

Is this right?

AJS.toInit(function(){
    AJS.MacroBrowser.setMacroJsOverride('macroName', {
        'field' : {
            'string' : function(param, options){
                var myParam = AJS.$('#id-of-parameter');
                var myParamParent = AJS.$('#id-of-parent-element');
                myParam.remove();

                var newParam = document.createElement("textarea");
                newParam.setAttribute('id', '#id-of-parameter');

                myParamParent.append(newParam);
            }
        }
    })
})