mirror of
https://github.com/rails/rails.git
synced 2022-11-09 12:12:34 -05:00
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
This commit is contained in:
parent
1752583531
commit
1a22fb59c9
4 changed files with 69 additions and 0 deletions
|
@ -1,5 +1,7 @@
|
||||||
*SVN*
|
*SVN*
|
||||||
|
|
||||||
|
* Added JavascriptHelper#periodically_call_remote in order to create areas of a page that update automatically at a set interval #945 [Jon Tirsen]
|
||||||
|
|
||||||
* Fixed Cache#expire_matched_fragments that couldn't recognize the difference between string and url_for options #1030 [skaes@web.de]
|
* Fixed Cache#expire_matched_fragments that couldn't recognize the difference between string and url_for options #1030 [skaes@web.de]
|
||||||
|
|
||||||
* Added simulation of @request.request_uri in functional tests #1038 [Jamis Buck]
|
* Added simulation of @request.request_uri in functional tests #1038 [Jamis Buck]
|
||||||
|
|
|
@ -71,6 +71,15 @@ module ActionView
|
||||||
link_to_function(name, remote_function(options), html_options)
|
link_to_function(name, remote_function(options), html_options)
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Periodically calls the specified url (<tt>options[:url]</tt>) every <tt>options[:frequency]</tt> seconds (default is 10).
|
||||||
|
# Usually used to update a specified div (<tt>options[:update]</tt>) 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
|
# 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
|
# 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).
|
# will work just like a regular submission as viewed by the receiving side (all elements available in @params).
|
||||||
|
|
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
29
railties/html/javascripts/prototype.js
vendored
29
railties/html/javascripts/prototype.js
vendored
|
@ -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();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in a new issue