diff options
-rw-r--r-- | actionpack/CHANGELOG | 8 | ||||
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 13 | ||||
-rw-r--r-- | actionpack/test/template/javascript_helper_test.rb | 13 |
3 files changed, 32 insertions, 2 deletions
diff --git a/actionpack/CHANGELOG b/actionpack/CHANGELOG index e21677861a..dfe6993714 100644 --- a/actionpack/CHANGELOG +++ b/actionpack/CHANGELOG @@ -1,5 +1,13 @@ *SVN* +* Fixed JavaScriptHelper#link_to_function and JavaScriptHelper#button_to_function to have the script argument be optional [DHH]. So what used to require a nil, like this: + + link_to("Hider", nil, :class => "hider_link") { |p| p[:something].hide } + + ...can be written like this: + + link_to("Hider", :class => "hider_link") { |p| p[:something].hide } + * Update to script.aculo.us 1.6.3 [Thomas Fuchs] * Update to Prototype 1.5.0_rc1 [sam] diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 8777b51b9a..3f0a462092 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -79,7 +79,10 @@ module ActionView # }; # return false;">Show me more</a> # - def link_to_function(name, function = '', html_options = {}, &block) + def link_to_function(name, *args, &block) + html_options = args.last.is_a?(Hash) ? args.pop : {} + function = args[0] || '' + html_options.symbolize_keys! function = update_page(&block) if block_given? content_tag( @@ -104,7 +107,13 @@ module ActionView # button_to_function "Details" do |page| # page[:details].visual_effect :toggle_slide # end - def button_to_function(name, function = '', html_options = {}, &block) + # button_to_function "Details", :class => "details_button" do |page| + # page[:details].visual_effect :toggle_slide + # end + def button_to_function(name, *args, &block) + html_options = args.last.is_a?(Hash) ? args.pop : {} + function = args[0] || '' + html_options.symbolize_keys! function = update_page(&block) if block_given? tag(:input, html_options.merge({ diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb index d186d11dd5..7cb08ec498 100644 --- a/actionpack/test/template/javascript_helper_test.rb +++ b/actionpack/test/template/javascript_helper_test.rb @@ -38,6 +38,12 @@ class JavaScriptHelperTest < Test::Unit::TestCase assert_dom_equal %(<a href="#" onclick="Element.update("header", "<h1>Greetings</h1>");; return false;">Greet me!</a>), html end + def test_link_to_function_with_rjs_block_and_options + html = link_to_function( "Greet me!", :class => "updater" ) do |page| + page.replace_html 'header', "<h1>Greetings</h1>" + end + assert_dom_equal %(<a href="#" class="updater" onclick="Element.update("header", "<h1>Greetings</h1>");; return false;">Greet me!</a>), html + end def test_button_to_function assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />), @@ -50,4 +56,11 @@ class JavaScriptHelperTest < Test::Unit::TestCase end assert_dom_equal %(<input type="button" onclick="Element.update("header", "<h1>Greetings</h1>");;" value="Greet me!" />), html end + + def test_button_to_function_with_rjs_block_and_options + html = button_to_function( "Greet me!", :class => "greeter" ) do |page| + page.replace_html 'header', "<h1>Greetings</h1>" + end + assert_dom_equal %(<input type="button" class="greeter" onclick="Element.update("header", "<h1>Greetings</h1>");;" value="Greet me!" />), html + end end |