From 341d34cd50ab1d807a9d515058d1da8fe75deb01 Mon Sep 17 00:00:00 2001 From: David Heinemeier Hansson Date: Sat, 31 Dec 2005 03:50:08 +0000 Subject: Added that JavaScriptHelper#link_to_function will honor existing :onclick definitions when adding the function call [DHH] git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3364 5ecf4fe2-1ee6-0310-87b1-e25e094e27de --- actionpack/lib/action_view/helpers/javascript_helper.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'actionpack/lib/action_view/helpers') diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 033aff5044..7dccecda13 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -48,9 +48,13 @@ module ActionView # link_to_function "Greeting", "alert('Hello world!')" # link_to_function(image_tag("delete"), "if confirm('Really?'){ do_delete(); }") def link_to_function(name, function, html_options = {}) + html_options.symbolize_keys! content_tag( "a", name, - {:href => "#", :onclick => "#{function}; return false;"}.merge(html_options.symbolize_keys) + html_options.merge({ + :href => html_options[:href] || "#", + :onclick => "#{function};#{html_options[:onclick] ? " #{html_options[:onclick]};" : ""} return false;" + }) ) end -- cgit v1.2.3