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@3365 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent 341d34c commit 89d8afa2c4f256ffb84b6c9e521546b5dd3e60d8 @dhh dhh committed Dec 31, 2005
View
2 actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -53,7 +53,7 @@ def link_to_function(name, function, html_options = {})
"a", name,
html_options.merge({
:href => html_options[:href] || "#",
- :onclick => "#{function};#{html_options[:onclick] ? " #{html_options[:onclick]};" : ""} return false;"
+ :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function}; return false;"
})
)
end
View
2 actionpack/test/template/javascript_helper_test.rb
@@ -27,7 +27,7 @@ def test_link_to_function
end
def test_link_to_function_with_existing_onclick
- assert_dom_equal %(<a href="#" onclick="alert('Hello world!'); confirm('Sanity!'); return false;">Greeting</a>),
+ assert_dom_equal %(<a href="#" onclick="confirm('Sanity!'); alert('Hello world!'); return false;">Greeting</a>),
link_to_function("Greeting", "alert('Hello world!')", :onclick => "confirm('Sanity!')")
end
end

0 comments on commit 89d8afa

Please sign in to comment.