[Seaside] Re: Problem with Scriptaculous

Lukas Renggli renggli at gmail.com
Mon Jun 11 04:40:54 UTC 2007


> Looking at the resultant javascript I worked out roughly what was going on.
>
> ((SUElement on: html) id: 'workflow'_ property:' offsetTop')
>
> was generating something like Element('workflow').toggle['offsetTop']
>
> The first time it would not work (well it would not get the correct
> answer), the second time it did. Does this make any sense?

Oups, I missed that. In this case it makes sense. The first time you
toggle it gets hidden and therefor returns the wrong result (a hidden
element has offset 0). The second time it gets shown again and the new
offset is read. I just wonder why I didn't observe that yesterday when
I tried it out :-/

> I could not find a way to get rid of the call to toggle, and even when I
> hacked the code to allow SUElement-#method to return nil,
> Element('workflow)['offsetTop'] didnt seem to work. So I ended up using

Yes these default methods are nasty. This is not the first time I got
bitten. These methods date back to the very first versions of
Scriptaculous, where the JavaScript framework was not that composable
at all. Nowadays this sort of contradicts the free composability of
the elements. I will try to refactor that, let's see if this can be
done without breaking some older code.

The problem is that offsetTop is not a Scriptaculous method, but one
from DOM. Therefor it cannot be written the same way other
Scriptaculous functions can. The shortest form would probably be:

    $('id1').offsetTop

> I didnt receive a fileOut with your email.

Sorry, I forgot to attach it and now I don't have it anymore. Anyway,
I described my changes in the mail.

> I do want to update several things perhaps 5 items, not just the
> co-ordinates, is that achievable using this scheme?
>
> e.g.
>
>      onClick: (html updater id: 'co-ordinates'; on:
> #renderCoordinatesOn: of: self );
>         onClick: (html updater id: 'workflow-focus'; on: #renderFocusOn:
> of: self );

Yes that's possible but highly inefficient (5 independent requests)
and there is no guarantee of the order in which all these updates will
be performed. So I suggest that you use the evaluator, that is made to
do such complicated things in one go (one single request):

   onClick: (html evaluator

      " data pushed to the server "
      callback: [ :v | ... ] value: ...;
      callback: [ :v | ... ] value: ...;
      callback: [ :v | ... ] value: ...;
      ...

      " response script s sent back to the client
        (in this case the contents of id1..id3 is updated) "
      callback: [ :s |
          s element id: 'id1'; render: [ :r | ... ].
          s element id: 'id2'; render: [ :r | ... ].
          s element id: 'id3'; render: [ :r | ... ].
          ... ])


HTH,
Lukas

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


More information about the Seaside mailing list