You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@wicket.apache.org by Anton Veretennikov <an...@gmail.com> on 2008/11/26 05:26:44 UTC

Javascript must be called once at the end

Hi,

JavaScript source files itself are inserted using <wicket:head> in
CodeHighlightPanel's html.
It's great that they are included only once though multiple
CodeHighlightPanel's instances have it.
How to make alone call

  <script language="javascript">
    dp.SyntaxHighlighter.HighlightAll('code');
  </script>

at the end of <body>?

And not to have it at all if no CodeHighlightPanel was in output?

I tested that several calls of it produce unexpected result.

Tony.

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Javascript must be called once at the end

Posted by Anton Veretennikov <an...@gmail.com>.
Great! It works for panel also!
Thank you.

> The easiest thing would be to just add an AbstractBehavior, override
> renderHeader and call
> renderOnDomReadyJavascript("dp.SyntaxHighlighter.HighlightAll('code');");
>
> If it's the exact same string, it can be added as many times as you want and
> Wicket will automatically only render it once.  Try this:
>
> public class HomePage extends WebPage {
>    private static final long serialVersionUID = 1L;
>    public HomePage(final PageParameters parameters) {
>        add(new Label("message", "If you see this message wicket is properly
> configured and running"));
>        add(new MyJSBehavior());
>        add(new MyJSBehavior());
>    }
>    private static class MyJSBehavior extends AbstractBehavior {
>        private static final long serialVersionUID = 1L;
>        @Override
>        public void renderHead(IHeaderResponse response) {
>            super.renderHead(response);
>            response.renderOnDomReadyJavascript("alert('test');");
>        }
>    }
> }
>
>
> --
> Jeremy Thomerson
> http://www.wickettraining.com
>
>
> On Tue, Nov 25, 2008 at 10:26 PM, Anton Veretennikov <
> anton.veretennikov@gmail.com> wrote:
>
>> Hi,
>>
>> JavaScript source files itself are inserted using <wicket:head> in
>> CodeHighlightPanel's html.
>> It's great that they are included only once though multiple
>> CodeHighlightPanel's instances have it.
>> How to make alone call
>>
>>  <script language="javascript">
>>    dp.SyntaxHighlighter.HighlightAll('code');
>>  </script>
>>
>> at the end of <body>?
>>
>> And not to have it at all if no CodeHighlightPanel was in output?
>>
>> I tested that several calls of it produce unexpected result.
>>
>> Tony.
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
>> For additional commands, e-mail: users-help@wicket.apache.org
>>
>>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
For additional commands, e-mail: users-help@wicket.apache.org


Re: Javascript must be called once at the end

Posted by Jeremy Thomerson <je...@wickettraining.com>.
The easiest thing would be to just add an AbstractBehavior, override
renderHeader and call
renderOnDomReadyJavascript("dp.SyntaxHighlighter.HighlightAll('code');");

If it's the exact same string, it can be added as many times as you want and
Wicket will automatically only render it once.  Try this:

public class HomePage extends WebPage {
    private static final long serialVersionUID = 1L;
    public HomePage(final PageParameters parameters) {
        add(new Label("message", "If you see this message wicket is properly
configured and running"));
        add(new MyJSBehavior());
        add(new MyJSBehavior());
    }
    private static class MyJSBehavior extends AbstractBehavior {
        private static final long serialVersionUID = 1L;
        @Override
        public void renderHead(IHeaderResponse response) {
            super.renderHead(response);
            response.renderOnDomReadyJavascript("alert('test');");
        }
    }
}


-- 
Jeremy Thomerson
http://www.wickettraining.com


On Tue, Nov 25, 2008 at 10:26 PM, Anton Veretennikov <
anton.veretennikov@gmail.com> wrote:

> Hi,
>
> JavaScript source files itself are inserted using <wicket:head> in
> CodeHighlightPanel's html.
> It's great that they are included only once though multiple
> CodeHighlightPanel's instances have it.
> How to make alone call
>
>  <script language="javascript">
>    dp.SyntaxHighlighter.HighlightAll('code');
>  </script>
>
> at the end of <body>?
>
> And not to have it at all if no CodeHighlightPanel was in output?
>
> I tested that several calls of it produce unexpected result.
>
> Tony.
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: users-unsubscribe@wicket.apache.org
> For additional commands, e-mail: users-help@wicket.apache.org
>
>