aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/javascripts
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-04-07 06:43:21 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-04-07 06:43:21 +0000
commit1a22fb59c944aee70c968688dc0440596670076b (patch)
treea1d360a3307d3f83cd0f475816ad84951e17dbd6 /actionpack/lib/action_view/helpers/javascripts
parent17525835312cdf033db1b6593274a2e4f54bdb1e (diff)
downloadrails-1a22fb59c944aee70c968688dc0440596670076b.tar.gz
rails-1a22fb59c944aee70c968688dc0440596670076b.tar.bz2
rails-1a22fb59c944aee70c968688dc0440596670076b.zip
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
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascripts')
-rw-r--r--actionpack/lib/action_view/helpers/javascripts/prototype.js29
1 files changed, 29 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/javascripts/prototype.js b/actionpack/lib/action_view/helpers/javascripts/prototype.js
index 5dc41e36dd..1ab50882c4 100644
--- a/actionpack/lib/action_view/helpers/javascripts/prototype.js
+++ b/actionpack/lib/action_view/helpers/javascripts/prototype.js
@@ -613,3 +613,32 @@ Effect.Appear.prototype = {
}
}
+/*--------------------------------------------------------------------------*/
+
+PeriodicalExecuter = Class.create();
+PeriodicalExecuter.prototype = {
+ initialize: function(what, frequency) {
+ this.what = what;
+ this.frequency = frequency;
+ this.currentlyExecuting = false;
+
+ this.registerCallback();
+ },
+
+ registerCallback: function() {
+ setTimeout(this.onTimerEvent.bind(this), this.frequency * 1000);
+ },
+
+ onTimerEvent: function() {
+ if (!this.currentlyExecuting) {
+ try {
+ this.currentlyExecuting = true;
+ this.what();
+ } finally {
+ this.currentlyExecuting = false;
+ }
+ }
+
+ this.registerCallback();
+ }
+}