Topic: RJS page.delay timing issues

Hi.

Has anyone ran into issues with the timing of page.delay.  I have been testing in firefox, for the most part, and it seems that there is no reliability on when the page.delay timings kick in. 

What happens is that sometimes it will work fine, and the countdown looks great; other times it will just jump to the end and display everything at once, other times it will be jerky.  I'm on a pretty powerful machine, so the javascript shouldn't be causing system slowdowns, from what I can tell...

Maybe I'm using it wrong?

info.rjs

      
    page.visual_effect :fade, 'Infoname', :duration => 0.5
    page.visual_effect :fade, 'InfoDescription', :duration => 0.5
    page.visual_effect :fade, 'InfoButton', :duratin => 0.5
    page.delay(1.0) do
      page.insert_html :top, 'countdown', 'Info in..'
    end
    page.delay(2.0) do
      page.insert_html :bottom, 'countdown', '3'
    end
    page.delay(2.3) do
      page.insert_html :bottom, 'countdown', '.'
    end
    page.delay(2.6) do
      page.insert_html :bottom, 'countdown', '.'
    end
    page.delay(3.0) do
      page.insert_html :bottom, 'countdown', '2'
    end
    page.delay(3.3) do
      page.insert_html :bottom, 'countdown', '.'
    end
    page.delay(3.6) do
      page.insert_html :bottom, 'countdown', '.'
    end
    page.delay(4.0) do
      page.insert_html :bottom, 'countdown', '1'
    end
    page.delay(4.5) do
      page.replace_html 'countdown', '<div id="countdownGO">GO!</div>'
      page.visual_effect :puff, 'countdown', :duration => 0.5
    end
    page.delay(5.0) do 
  page.visual_effect :fade, 'profile-indicator'
  page.replace_html 'info', :partial => 'info/test'
  end

Any ideas?  Am I using the RJS template in a way it wasn't designed, or extremely inefficient, that would cause it to be so erratic?

Thank you for your help.

Re: RJS page.delay timing issues

Just to post a reply on how I fixed this, and a lesson learned.

The first thing; in the code above, I'm making a bad assumption that Firefox, or any browser, would initiate all of the page.delay's at the same time.  This was not a good assumption to make.  The solution to this is to kick off the execution in succession, and increment the time that way.

Here is the code that seems to be working, it's still kind of ugly though:

page.visual_effect :fade, 'Infoname', :duration => 0.5
page.visual_effect :fade, 'InfoDescription', :duration => 0.5
page.visual_effect :fade, 'InfoButton', :duration => 0.5
page.delay(1.0) do
  page.insert_html :top, 'countdown', 'Info in..'
  page.delay(1.0) do
    page.insert_html :bottom, 'countdown', '3'
    page.delay(0.3) do
      page.insert_html :bottom, 'countdown', '.'
      page.delay(0.3) do
        page.insert_html :bottom, 'countdown', '.'
        page.delay(0.3) do
          page.insert_html :bottom, 'countdown', '2'
          page.delay(0.3) do
            page.insert_html :bottom, 'countdown', '.'
            page.delay(0.3) do
              page.insert_html :bottom, 'countdown', '.'
              page.delay(0.3) do
                page.insert_html :bottom, 'countdown', '1'
                page.delay(0.3) do
                  page.replace_html 'countdown', '<div id="countdownGO">GO!</div>'
                  page.visual_effect :puff, 'countdown', :duration => 0.5
                  page.delay(0.3) do
                    page.visual_effect :fade, 'profile-indicator'
                    page.replace_html 'info', :partial => 'info/test'
                  end
                end
              end
            end
          end
        end
      end
    end
  end
end

It was also suggested to use this at the end of each page.delay line

, :queue =>  "end"

Have a great day!

Re: RJS page.delay timing issues

You can clean this up quite a bit with a helper method like this:

# in helper
def countdown(strings, delay = 0.3, &block)
  page.insert_html :bottom, :countdown, strings.shift
  if strings.empty?
    page.delay(delay, &block)
  else
    page.delay(delay) { countdown(strings, delay, &block) }
  end
end

# in rjs file
page.delay(1.0) do
  page.insert_html :top, 'countdown', 'Info in..'
  page.delay(1.0) do
    coountdown(%w[3 . . 2 . . 1]) do
      page.replace_html 'countdown', '<div id="countdownGO">GO!</div>'
      page.visual_effect :puff, 'countdown', :duration => 0.5
      page.delay(0.3) do
        page.visual_effect :fade, 'profile-indicator'
        page.replace_html 'info', :partial => 'info/test'
      end
    end
  end
end


Untested.

Railscasts - Free Ruby on Rails Screencasts

Re: RJS page.delay timing issues

I'll give it a try, Ryan.

Thank you,