From de1f231c32155c10e4b03c3b861a885786dc9f59 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Mon, 27 Jun 2005 05:29:47 +0000 Subject: Added event-based observations when frequency is not set on observe_field/form #1474 [flash@vanklinkenbergsoftware.nl] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1532 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/CHANGELOG | 2 ++ .../lib/action_view/helpers/javascript_helper.rb | 21 ++++++++++++++++----- 2 files changed, 18 insertions(+), 5 deletions(-) (limited to 'actionpack') 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: - # :frequency:: The frequency (in seconds) at which changes to - # this field will be detected. # :url:: +url_for+-style options for the action to call # when the field has changed. # # Additional options are: + # :frequency:: 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. # :update:: 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 :with 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 = '" end -- cgit v1.2.3