Forum: Ruby on Rails RJS

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
RJS
Jm G. (Guest)
on 2006-02-08 14:43
I am playing with the new .rjs stuff in edge rails.
I am doing stuff like :
page.replace_html 'scoops_tot', @scoops.size

1. I want to add my own javascript functions to the page object.
Is it possible and how ?


2. I am trying to update several fields, but i would like a to have a
dekay between the updates :
@anoclicks.each{|aclick|
  page.replace_html 'click_number_'+aclick.scoop.id.to_s ,
aclick.scoop.clicks_tot.to_i + aclick.scoop.anoclicks_tot.to_i
  page.visual_effect :Pulsate, "click_me_#{aclick.scoop.id}"
}
Jon Evans (Guest)
on 2006-02-08 15:26
(Received via mailing list)
Hi,

On 8 Feb 2006, at 12:43, jm goom wrote:

I haven't used rjs yet, but I have got the "Rails Recipes" beta book
(well worth buying BTW).

> 1. I want to add my own javascript functions to the page object.
> Is it possible and how ?

Reading through the file*, I see this method which may be what you want:
   # Writes raw JavaScript to the page.
   def <<(javascript)
     @lines << javascript
   end

> 2. I am trying to update several fields, but i would like a to have a
> dekay between the updates :

You want something like this (from the book):

page.delay(3) do
   page.alert @rails_version
end

which I'm sure you can adapt for your purposes.

Jon

* actionpack/lib/action_view/helpers/prototype_helper.rb
Jm G. (Guest)
on 2006-02-08 16:08
Thank you for your answer
I have the book in front of me (the pdf of course)
I did not see this << method, but just found it in the last version of
the doc ! Great !

For the delay, i cannot get it working more than once.
I want to execute an effect for each item in an array and each time
apply the same delay... I am going to play with that << thing.

Thanks a lot :)
Kevin O. (Guest)
on 2006-02-08 16:50
jm goom wrote:
> Thank you for your answer
> I have the book in front of me (the pdf of course)
> I did not see this << method, but just found it in the last version of
> the doc ! Great !
>
> For the delay, i cannot get it working more than once.
> I want to execute an effect for each item in an array and each time
> apply the same delay... I am going to play with that << thing.
>
> Thanks a lot :)

I haven't tried it, but it may be possible to nest delay blocks.

page.delay(3) do
  page.do_something
  page.delay(3) do
    page.do_something_again
  end
end

_Kevin
Jm G. (Guest)
on 2006-02-08 17:56
I found a solution that is working great :

i = 0
@hp.each{ |hp|
  page.delay(i) do
    page.visual_effect :Fade, 'scoop_'+hp.id.to_s
    i+=1
  end
}

Thx for your help
Joe Van D. (Guest)
on 2006-02-08 18:05
(Received via mailing list)
On 2/8/06, jm goom <removed_email_address@domain.invalid> wrote:
> I found a solution that is working great :
>
> i = 0
> @hp.each{ |hp|
>   page.delay(i) do
>     page.visual_effect :Fade, 'scoop_'+hp.id.to_s
>     i+=1
>   end
> }

More ruby-like:

@hp.each_with_index do |hp, index|
    page.delay(index) do
        page.visual_effect :Fade, "scoop_#{ hp.id }"
    end
  end
This topic is locked and can not be replied to.