[Seaside] How to write jQuery $.ready scripts?

Lukas Renggli renggli at gmail.com
Sat Jan 2 10:12:14 UTC 2010


> So, I would like to have few jQuery operations executed when DOM is
> ready. My best so far is:
>
> renderContentOn: html
>        html script: (html jQuery
>                                ready: ( (html jQuery: #glavati)
>                                                text: 'Njurko';
>                                                on: 'click' do: 'alert("gotcha");' )).
>
>        html script: (html  jQuery
>                        ready: 'alert("aha");' ).
>
>        html heading
>                level: 1;
>                id: #glavati;
>                with: 'Gurko'.

Don't use the JQuery-ready function in Seaside. This gives
unpredictable results. As Julian suggested use #addLoadScript:,
Seaside has its own mechanism to execute scripts. Also check our
JQuery presentation for additional information:
<http://www.slideshare.net/esug/jquery-in-seaside>.

> Or I am doing it backwards and should put all that code in plain
> javascript file and just include it as is?

That is a possibility, but often not that practical if you have lots
of different fine grande behavior and interaction back with the
server.

> Am I missing something or there is no Seaside binding for
> jQuery(..).click() function? (I am using Dolphin port of Seaside which
> is 2.9.something)

There is #onClick: at least in the latest version of JQuery for Seaside.

So in the end your method should look like:

renderContentOn: html
       html document
               addLoadScript: 'alert("aha")'.
       html heading
               level: 1;
               script: (html jQuery this
                     text: 'Njurko';
                     onClick: 'alert("gotcha")');
               with: 'Gurko'.

Lukas

-- 
Lukas Renggli
http://www.lukas-renggli.ch


More information about the seaside mailing list