diff options
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/CHANGELOG | 2 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 21 |
2 files changed, 18 insertions, 5 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index ae8de12988..e30d645713 100644 --- a/actionpack/CHANGELOG +++ b/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] diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index a53b284c22..aeabef6a5d 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -176,12 +176,14 @@ module ActionView # 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,7 +195,11 @@ module ActionView # 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 @@ -201,7 +207,11 @@ module ActionView # 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 @@ module ActionView 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 |