From 1a22fb59c944aee70c968688dc0440596670076b Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Thu, 7 Apr 2005 06:43:21 +0000 Subject: Added JavascriptHelper#periodically_call_remote in order to create areas of a page that update automatically at a set interval #945 [Jon Tirsen] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1108 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/javascript_helper.rb | 9 +++++++++ 1 file changed, 9 insertions(+) (limited to 'actionpack/lib/action_view/helpers/javascript_helper.rb') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 59765f9737..ba418b15b3 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -71,6 +71,15 @@ module ActionView link_to_function(name, remote_function(options), html_options) end + # Periodically calls the specified url (options[:url]) every options[:frequency] seconds (default is 10). + # Usually used to update a specified div (options[:update]) with the results of the remote call. + # The options for specifying the target with :url and defining callbacks is the same as link_to_remote. + def periodically_call_remote(options = {}) + frequency = options[:frequency] || 10 # every ten seconds by default + code = "new PeriodicalExecuter(function() {#{remote_function(options)}}, #{frequency})" + content_tag("script", code, options[:html_options] || {}) + end + # Returns a form tag that will submit using XMLHttpRequest in the background instead of the regular # reloading POST arrangement. Even though it's using Javascript to serialize the form elements, the form submission # will work just like a regular submission as viewed by the receiving side (all elements available in @params). -- cgit v1.2.3