Permalink
Browse files

Added that JavaScriptHelper#link_to_function will honor existing :onc…

…lick definitions when adding the function call [DHH]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3364 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 00541f2 commit 341d34cd50ab1d807a9d515058d1da8fe75deb01 @dhh dhh committed Dec 31, 2005
View
@@ -1,5 +1,7 @@
*SVN*
+* Added that JavaScriptHelper#link_to_function will honor existing :onclick definitions when adding the function call [DHH]
+
* Added :disable_with option to FormTagHelper#submit_tag to allow for easily disabled submit buttons with different text [DHH]
* Make auto_link handle nil by returning quickly if blank? [Scott Barron]
@@ -48,9 +48,13 @@ module JavaScriptHelper
# 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
@@ -26,4 +26,8 @@ def test_link_to_function
link_to_function("Greeting", "alert('Hello world!')")
end
+ def test_link_to_function_with_existing_onclick
+ assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); confirm('Sanity!'); return false;">Greeting</a>),
+ link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
+ end
end

0 comments on commit 341d34c

Please sign in to comment.