Unobtrusive JavaScript

View: New views
3 Messages — Rating Filter:   Alert me  

Unobtrusive JavaScript

by Matthias Hryniszak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Hi there,

I was wondering if it'd be possible to generate the JavaScript for i.e.
AjaxLink components in such a way that the actual JS is not directly there
as onclick parameter. It's the idea of unobtrusive JavaScript makes the
markup a lot cleaner and easier to read.

A good example of such an unobtrusive JavaScript approach could be observed
in jQuery (http://docs.jquery.com/Events/click):

jQuery([item_selector]).click([handler]);

This binds the onclick event of an element to the given handler without
polluting the actual markup with stuff like

onclick="var
wcall=wicketAjaxGet('?wicket:interface=:0:link_inc::IBehaviorListener:0:',null,null,
function() {return Wicket.$('link__inc1') != null;}.bind(this));return
!wcall;"

which in turn makes reading the generated markup (a bit) harder if there are
lots of those on the page.


Best regards,
Matthias.

Re: Unobtrusive JavaScript

by igor.vaynberg :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

this is something planned for 1.5 or 1.6

-igor

On Wed, Sep 23, 2009 at 2:36 PM, Matthias Hryniszak
<matthias@...> wrote:

> Hi there,
>
> I was wondering if it'd be possible to generate the JavaScript for i.e.
> AjaxLink components in such a way that the actual JS is not directly there
> as onclick parameter. It's the idea of unobtrusive JavaScript makes the
> markup a lot cleaner and easier to read.
>
> A good example of such an unobtrusive JavaScript approach could be observed
> in jQuery (http://docs.jquery.com/Events/click):
>
> jQuery([item_selector]).click([handler]);
>
> This binds the onclick event of an element to the given handler without
> polluting the actual markup with stuff like
>
> onclick="var
> wcall=wicketAjaxGet('?wicket:interface=:0:link_inc::IBehaviorListener:0:',null,null,
> function() {return Wicket.$('link__inc1') != null;}.bind(this));return
> !wcall;"
>
> which in turn makes reading the generated markup (a bit) harder if there are
> lots of those on the page.
>
>
> Best regards,
> Matthias.
>

Re: Unobtrusive JavaScript

by Matthias Hryniszak :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

That's great! Thanks for the info!

Matthias.

2009/9/24 Igor Vaynberg <igor.vaynberg@...>

> this is something planned for 1.5 or 1.6
>
> -igor
>
> On Wed, Sep 23, 2009 at 2:36 PM, Matthias Hryniszak
> <matthias@...> wrote:
> > Hi there,
> >
> > I was wondering if it'd be possible to generate the JavaScript for i.e.
> > AjaxLink components in such a way that the actual JS is not directly
> there
> > as onclick parameter. It's the idea of unobtrusive JavaScript makes the
> > markup a lot cleaner and easier to read.
> >
> > A good example of such an unobtrusive JavaScript approach could be
> observed
> > in jQuery (http://docs.jquery.com/Events/click):
> >
> > jQuery([item_selector]).click([handler]);
> >
> > This binds the onclick event of an element to the given handler without
> > polluting the actual markup with stuff like
> >
> > onclick="var
> >
> wcall=wicketAjaxGet('?wicket:interface=:0:link_inc::IBehaviorListener:0:',null,null,
> > function() {return Wicket.$('link__inc1') != null;}.bind(this));return
> > !wcall;"
> >
> > which in turn makes reading the generated markup (a bit) harder if there
> are
> > lots of those on the page.
> >
> >
> > Best regards,
> > Matthias.
> >
>