Browse files

Added event-based observations when frequency is not set on observe_f…

…ield/form #1474 [flash@vanklinkenbergsoftware.nl]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1532 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c19b74d commit de1f231c32155c10e4b03c3b861a885786dc9f59 @dhh dhh committed Jun 27, 2005
Showing with 18 additions and 5 deletions.
  1. +2 −0 actionpack/CHANGELOG
  2. +16 −5 actionpack/lib/action_view/helpers/javascript_helper.rb
View
2 actionpack/CHANGELOG
@@ -1,5 +1,7 @@
*SVN*
+* Added event-based observations when frequency is not set on observe_field/form #1474 [flash@vanklinkenbergsoftware.nl]
+
* Added script.aculo.us Javascripts (controls.js, dragdrop.js, effects.js) (NEEDS MORE DESCRIPTION) #1509 [Thomas Fuchs]
* Fixed prototype to consider all fields it doesn't know as text (such as Safari's search) just like the browser in its serialization #1497 [Sean Treadway]
View
21 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -176,12 +176,14 @@ def define_javascript_functions
# an Ajax call when its contents have changed.
#
# Required +options+ are:
- # <tt>:frequency</tt>:: The frequency (in seconds) at which changes to
- # this field will be detected.
# <tt>:url</tt>:: +url_for+-style options for the action to call
# when the field has changed.
#
# Additional options are:
+ # <tt>:frequency</tt>:: The frequency (in seconds) at which changes to
+ # this field will be detected. Set this to a value
+ # greater than zero to use time based observation
+ # instead of event based observation.
# <tt>:update</tt>:: Specifies the DOM ID of the element whose
# innerHTML should be updated with the
# XMLHttpRequest response text.
@@ -193,15 +195,23 @@ def define_javascript_functions
# Additionally, you may specify any of the options documented in
# +link_to_remote.
def observe_field(field_id, options = {})
- build_observer('Form.Element.Observer', field_id, options)
+ if options[:frequency]
+ build_observer('Form.Element.Observer', field_id, options)
+ else
+ build_observer('Form.Element.EventObserver', form_id, options)
+ end
end
# Like +observe_field+, but operates on an entire form identified by the
# DOM ID +form_id+. +options+ are the same as +observe_field+, except
# the default value of the <tt>:with</tt> option evaluates to the
# serialized (request string) value of the form.
def observe_form(form_id, options = {})
- build_observer('Form.Observer', form_id, options)
+ if options[:frequency]
+ build_observer('Form.Observer', form_id, options)
+ else
+ build_observer('Form.EventObserver', form_id, options)
+ end
end
@@ -343,7 +353,8 @@ def build_observer(klass, name, options = {})
callback = remote_function(options)
javascript = '<script type="text/javascript">'
javascript << "new #{klass}('#{name}', "
- javascript << "#{options[:frequency]}, function(element, value) {"
+ javascript << "#{options[:frequency]}, " if options[:frequency]
+ javascript << "function(element, value) {"
javascript << "#{callback}})</script>"
end

0 comments on commit de1f231

Please sign in to comment.