[Seaside] Detect the position of a page div

Lukas Renggli renggli at gmail.com
Tue Sep 22 17:20:54 UTC 2009


There is a bit too much nested AJAX going on for me ;-)

>         script: ((html jQuery new draggable) onDrag: (
>
>                 (html jQuery ajax script: [:s | s add: ((s jQuery: #bobLeft)
> html: (s jQuery ajax callback: [(s jQuery: #bob) offset access: 'left']))]),
>                 (html jQuery ajax script: [:s | s add: ((s jQuery: #bobTop)
> html: (s jQuery ajax callback: [(s jQuery: #bob) offset access: 'top']))])
>
>             )
>         );

The message #html: expects aRenderable, such as a block or a string of
HTML, something that is generated by Seaside on the server. In your
case you just display the script and that is what you see in the
browser.

If you replace #html with #text: and remove the roundtrip to the
server this should already work:

  (html jQuery ajax script: [:s | s add: ((s jQuery: #bobLeft) text:
((s jQuery: #bob) offset access: 'left'))]),
  (html jQuery ajax script: [:s | s add: ((s jQuery: #bobTop) text:
((s jQuery: #bob) offset access: 'top'))])

Now it displays the coordinates, but very much delayed as the script
makes two round-trips to the server whenever you move the draggable
element. In fact, this round-trip is not needed at all. If you remove
all AJAX code the script becomes much simpler and faster. Furthermore,
if you use the navigation facilities of jQuery you don't need any of
the IDs and the script becomes:

html div
	script: (html jQuery new draggable onDrag:
		((html jQuery this find: ':first') text: (html jQuery this offsetLeft)) ,
		((html jQuery this find: ':last') text: (html jQuery this offsetTop)));
	with: [ html div: 'left'; div: 'top' ]

Note, I use #offsetLeft and #offsetTop here, two methods I added to
jQuery this morning after your post. You might want to update to the
latest code, or replace the calls with the old code  #access:

Cheers,
Lukas

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


More information about the seaside mailing list