diff options
Diffstat (limited to 'railties/html')
-rw-r--r-- | railties/html/javascripts/prototype.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/railties/html/javascripts/prototype.js b/railties/html/javascripts/prototype.js index 5dc41e36dd..1ab50882c4 100644 --- a/railties/html/javascripts/prototype.js +++ b/railties/html/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(); + } +} |