From e52e803a5577489022a752827f37dd2ab56a2ac9 Mon Sep 17 00:00:00 2001 From: Thomas Fuchs Date: Mon, 6 Nov 2006 09:40:30 +0000 Subject: Deprecate JavaScriptHelper#update_element_function, which is superseeded by RJS [Thomas Fuchs] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@5438 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/deprecated_helper.rb | 34 ++++++++++ .../lib/action_view/helpers/prototype_helper.rb | 75 ---------------------- 2 files changed, 34 insertions(+), 75 deletions(-) create mode 100644 actionpack/lib/action_view/helpers/deprecated_helper.rb (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/deprecated_helper.rb b/actionpack/lib/action_view/helpers/deprecated_helper.rb new file mode 100644 index 0000000000..04392f5b04 --- /dev/null +++ b/actionpack/lib/action_view/helpers/deprecated_helper.rb @@ -0,0 +1,34 @@ +module ActionView + module Helpers + module PrototypeHelper + + def update_element_function(element_id, options = {}, &block) + content = escape_javascript(options[:content] || '') + content = escape_javascript(capture(&block)) if block + + javascript_function = case (options[:action] || :update) + when :update + if options[:position] + "new Insertion.#{options[:position].to_s.camelize}('#{element_id}','#{content}')" + else + "$('#{element_id}').innerHTML = '#{content}'" + end + + when :empty + "$('#{element_id}').innerHTML = ''" + + when :remove + "Element.remove('#{element_id}')" + + else + raise ArgumentError, "Invalid action, choose one of :update, :remove, :empty" + end + + javascript_function << ";\n" + options[:binding] ? concat(javascript_function, options[:binding]) : javascript_function + end + deprecate :update_element_function => "use RJS instead" + + end + end +end \ No newline at end of file diff --git a/actionpack/lib/action_view/helpers/prototype_helper.rb b/actionpack/lib/action_view/helpers/prototype_helper.rb index f26b673fbc..3c28173462 100644 --- a/actionpack/lib/action_view/helpers/prototype_helper.rb +++ b/actionpack/lib/action_view/helpers/prototype_helper.rb @@ -204,81 +204,6 @@ module ActionView tag("input", options[:html], false) end - # Returns a JavaScript function (or expression) that'll update a DOM - # element according to the options passed. - # - # * :content: The content to use for updating. Can be left out - # if using block, see example. - # * :action: Valid options are :update (assumed by default), - # :empty, :remove - # * :position If the :action is :update, you can optionally - # specify one of the following positions: :before, :top, :bottom, - # :after. - # - # Examples: - # <%= javascript_tag(update_element_function("products", - # :position => :bottom, :content => "

New product!

")) %> - # - # <% replacement_function = update_element_function("products") do %> - #

Product 1

- #

Product 2

- # <% end %> - # <%= javascript_tag(replacement_function) %> - # - # This method can also be used in combination with remote method call - # where the result is evaluated afterwards to cause multiple updates on - # a page. Example: - # - # # Calling view - # <%= form_remote_tag :url => { :action => "buy" }, - # :complete => evaluate_remote_response %> - # all the inputs here... - # - # # Controller action - # def buy - # @product = Product.find(1) - # end - # - # # Returning view - # <%= update_element_function( - # "cart", :action => :update, :position => :bottom, - # :content => "

New Product: #{@product.name}

")) %> - # <% update_element_function("status", :binding => binding) do %> - # You've bought a new product! - # <% end %> - # - # Notice how the second call doesn't need to be in an ERb output block - # since it uses a block and passes in the binding to render directly. - # This trick will however only work in ERb (not Builder or other - # template forms). - # - # See also JavaScriptGenerator and update_page. - def update_element_function(element_id, options = {}, &block) - content = escape_javascript(options[:content] || '') - content = escape_javascript(capture(&block)) if block - - javascript_function = case (options[:action] || :update) - when :update - if options[:position] - "new Insertion.#{options[:position].to_s.camelize}('#{element_id}','#{content}')" - else - "$('#{element_id}').innerHTML = '#{content}'" - end - - when :empty - "$('#{element_id}').innerHTML = ''" - - when :remove - "Element.remove('#{element_id}')" - - else - raise ArgumentError, "Invalid action, choose one of :update, :remove, :empty" - end - - javascript_function << ";\n" - options[:binding] ? concat(javascript_function, options[:binding]) : javascript_function - end - # Returns 'eval(request.responseText)' which is the JavaScript function # that form_remote_tag can call in :complete to evaluate a multiple # update return document using update_element_function calls. -- cgit v1.2.3