From ebb070e0786994ff96ec08507b169014110740d3 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 12 Mar 2005 02:59:12 +0000 Subject: Put it in the right module git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@890 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- .../lib/action_view/helpers/javascript_helper.rb | 264 +++++++++++---------- 1 file changed, 134 insertions(+), 130 deletions(-) diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 078935af3f..7e85519345 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -1,160 +1,164 @@ require File.dirname(__FILE__) + '/tag_helper' -# You must call <%= define_javascript_functions %> in your application before using these helpers. -module JavascriptHelper - def link_to_display_toggle(name, tags, html_options = {}) - toggle_functions = [ tags ].flatten.collect { |tag| "toggle_display_by_id('#{tag}'); " }.join - content_tag( - "a", name, - html_options.symbolize_keys.merge(:href => "#", :onclick => "#{toggle_functions}; #{html_options['onclick']}; return false;") - ) - end +module ActionView + module Helpers + # You must call <%= define_javascript_functions %> in your application before using these helpers. + module JavascriptHelper + def link_to_toggle_display(name, tags, html_options = {}) + toggle_functions = [ tags ].flatten.collect { |tag| "toggle_display_by_id('#{tag}'); " }.join + content_tag( + "a", name, + html_options.symbolize_keys.merge(:href => "#", :onclick => "#{toggle_functions}; #{html_options['onclick']}; return false;") + ) + end - def link_to_function(name, function, html_options = {}) - content_tag( - "a", name, - html_options.symbolize_keys.merge(:href => "#", :onclick => "#{function}; return false;") - ) - end + def link_to_function(name, function, html_options = {}) + content_tag( + "a", name, + html_options.symbolize_keys.merge(:href => "#", :onclick => "#{function}; return false;") + ) + end - def link_to_remote(name, options = {}) - link_to_function(name, remote_function(options)) - end + def link_to_remote(name, options = {}) + link_to_function(name, remote_function(options)) + end - def form_remote_tag(options = {}) - options[:form] = true + def form_remote_tag(options = {}) + options[:form] = true - options[:html] ||= { } - options[:html][:onsubmit] = "#{remote_function(options)}; return false;" + options[:html] ||= { } + options[:html][:onsubmit] = "#{remote_function(options)}; return false;" - tag("form", options[:html], true) - end + tag("form", options[:html], true) + end + + def define_javascript_functions + <<-EOF + -EOF - end - - private - def remote_function(options) - function = options[:update] ? - "update_with_response('#{options[:update]}', '#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" : - "xml_request('#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" - - function = "#{options[:before]};#{function}" if options[:before] - function = "#{function};#{options[:after]}" if options[:after] + + EOF + end + + private + def remote_function(options) + function = options[:update] ? + "update_with_response('#{options[:update]}', '#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" : + "xml_request('#{url_for(options[:url])}'#{', Form.serialize(this)' if options[:form]})" + + function = "#{options[:before]};#{function}" if options[:before] + function = "#{function};#{options[:after]}" if options[:after] - return function + return function + end end + end end \ No newline at end of file -- cgit v1.2.3