2

かなり基本的なアイデアですが、誰かがページにアクセスしたときにポップアップ ウィンドウを表示したいと考えています。サンプルコードを書きました。実際に私がやりたいのは、本文を持つマクロタイプのプラグインを作成して、テキスト、リンク、およびさまざまな要素を追加できるようにすることです。これにより、それらがポップアップ ウィンドウに表示されます。

これは、ページにアクセスしたときにポップアップウィンドウを表示できたコードですが、「getBodyType()」として「PLAIN_TEXT」を選択した場合です。フォーマットされていないテキストが表示され、「RICH_TEXT」を選択すると何も表示されません。助けてください!

package com.elixir;

import com.atlassian.confluence.content.render.xhtml.ConversionContext;
import com.atlassian.confluence.content.render.xhtml.XhtmlException;
import com.atlassian.confluence.macro.Macro;
import com.atlassian.confluence.macro.MacroExecutionException;
import com.atlassian.confluence.xhtml.api.MacroDefinition;
import com.atlassian.confluence.xhtml.api.MacroDefinitionHandler;
import com.atlassian.confluence.xhtml.api.XhtmlContent;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

public class MyMacro implements Macro
{
    private final XhtmlContent xhtmlUtils;

    public MyMacro(XhtmlContent xhtmlUtils)
    {
        this.xhtmlUtils = xhtmlUtils;
    }

    @Override
    public BodyType getBodyType()
    {
        return BodyType.RICH_TEXT;
    }

    @Override
    public OutputType getOutputType()
    {
        return OutputType.BLOCK;
    }

    @Override
    public String execute(Map<String, String> parameters, String bodyContent, ConversionContext conversionContext) throws MacroExecutionException
    {
        String body = conversionContext.getEntity().getBodyAsString();

        final List<MacroDefinition> macros = new ArrayList<MacroDefinition>();

        try
        {
            xhtmlUtils.handleMacroDefinitions(body, conversionContext, new MacroDefinitionHandler()
            {
                @Override
                public void handle(MacroDefinition macroDefinition)
                {
                    macros.add(macroDefinition);
                }
            });
        }
        catch (XhtmlException e)
        {
            throw new MacroExecutionException(e);
        }

        StringBuilder builder = new StringBuilder();
        if (!macros.isEmpty())
        {
            for (MacroDefinition defn : macros) {
                builder.append("<script>AJS.$(document).ready(function() {var popup2 = AJS.popup({width:400, height:200, id:'my-popup2', closeOnOutsideClick: true});");
                builder.append("$('#my-popup2').css({padding:4});$('#my-popup2').html(\"").append(defn.getBody()).append("\");");
                builder.append("popup2.show();});</script>");

            }
        }
        else
        {
            builder.append("Body not defined");
        }

        return builder.toString();
    }
}
4

1 に答える 1

2

hasBody='true'bodyType='raw'またはbodyType='rendered'、およびoutputType='html'またはが必要だと思いますoutputType='wiki'

このソリューションを実装する方法の例を次に示します: https://answers.atlassian.com/questions/93630/user-macro-module-body-parameter

于 2013-03-18T13:53:29.427 に答える