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

Lukas Renggli renggli at gmail.com
Sat Jan 2 13:06:32 UTC 2010

> On Sat, Jan 2, 2010 at 11:12 AM, Lukas Renggli <renggli at gmail.com> wrote:
>> 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>.

In fact there is also a video, the slides alone are probably not that useful:


> ah, this presentation is great! One question though, you say in
> presentation that we should forget about unobtrusive javascript. Is it
> that you consider it somehow harmfull or just not that important in
> Seaside, and why?

It is just not that important. In Seaside we try to encapsulate views
as much as possible in components and keep them independent of each
other and reusable in different contexts. Also when you want to have
interaction from client to server, the whole unobtrusive thing gets in
the way.

There is nothing that prevents you from using unobtrusive Javascript.
If you want you can still use it, especially for simple interactions
and effects you might still find it useful.

> as for addLoadScript, it seems to attach itself to body onLoad DOM
> event. Am I correct that this will execute only after everything has
> been downoloaded, including banners and such? In that case I would
> rather use jQUery.ready() since it would provide much quicker and
> reliable execution. But if you say it is off limits than I should
> forget about it. Is there maybe some cheatsheet that would allow me to
> use .ready safely with Seaside?

The problem is that when you use the JQuery ready-function (or for
that matter the Prototype dom:ready event) things become
unpredictable. Seaside cannot guarantee anymore the order in which
scripts get executed, if you are not a Javascript expert you likely
run into problems ...

I've however created an issue (for this long known problem) right
after I replied to your mail this morning:

>> There is #onClick: at least in the latest version of JQuery for Seaside.
> yes, but that also bounds to DOM onClick, instead of using
> jQuery.click which might be argued to be more flexible (allows easy
> attachment of several handlers), and to some extent normalizes
> incompatibilities in browser event handlings.

No, that #onClick: is on the JQuery object, it results in exactly the
same behavior as your call to #on:do:.

Also note that Seaside automatically supports multiple #onClick: calls
on DOM elements, so you can safely call it multiple times. The scripts
will just concatenated.


Lukas Renggli

More information about the seaside mailing list