Phlip
2006-Dec-01 23:56 UTC
borrowing periodically_call_remote (and update_page!!) for an in-page timer
Railoids: The following is either a FAQ, a clever code snippet, a plea for help, or a candidate for simplification, depending on the reaction it generates. Guess what this does: <span id=''abuse_me'' style=''background-color: orange;''> whip me beat me <br/> make me install oracle </span> <%= periodically_call_remote( :frequency => 5, :with => ''new Effect.Shake("abuse_me")'' ) %> It bypasses Ajax, doesn''t call remote, it simply creates a timer that shakes our SPAN (not DIV!) every five minutes. (Those of us who don''t want our websites to look like the cheapest of untargeted web ads may think of an action better than shaking!) Question: Is this actually more portable, robust, whatever, than calling a lowly setTimeout()? At least I don''t need to reset it. Are there any other benefits? (Technical question: Is a better method than :with available to call the timed method?) Now try this: <%= periodically_call_remote( :frequency => 5, :with => ''shakes()'' ) %> <script> function shakes() { <% update_page do |page| page.visual_effect :shake, ''abuse_me'' end %> } </script> Oookay. Now I reach out to RJS for the JavaScript. If the contents of shakes() were, again, more useful, then I might need them to be more browser-neutral. I am tired of writing raw JavaScript from scratch and then letting my various browsers vote on it. Thats what Script.aculo.us did for us! (Right?) (And how much of the <script> tags and function shakes() {} lines could I have pushed inside that render :update? Is this technique an awesome discovery of mine? Or have I gone astray and need simplifying?? -- Phlip http://www.greencheese.us/ZeekLand <-- NOT a blog!!! --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---