aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Heinemeier Hansson <david@loudthinking.com>2005-12-31 03:51:43 +0000
committerDavid Heinemeier Hansson <david@loudthinking.com>2005-12-31 03:51:43 +0000
commit89d8afa2c4f256ffb84b6c9e521546b5dd3e60d8 (patch)
tree94891dfc441d91381d1e4aef944c7936ffcf079e
parent341d34cd50ab1d807a9d515058d1da8fe75deb01 (diff)
downloadrails-89d8afa2c4f256ffb84b6c9e521546b5dd3e60d8.tar.gz
rails-89d8afa2c4f256ffb84b6c9e521546b5dd3e60d8.tar.bz2
rails-89d8afa2c4f256ffb84b6c9e521546b5dd3e60d8.zip
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@3365 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb2
-rw-r--r--actionpack/test/template/javascript_helper_test.rb2
2 files changed, 2 insertions, 2 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index 7dccecda13..3be96db001 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -53,7 +53,7 @@ module ActionView
"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
diff --git a/actionpack/test/template/javascript_helper_test.rb b/actionpack/test/template/javascript_helper_test.rb
index 6a01bd14b2..ef830e4e98 100644
--- a/actionpack/test/template/javascript_helper_test.rb
+++ b/actionpack/test/template/javascript_helper_test.rb
@@ -27,7 +27,7 @@ class JavaScriptHelperTest < Test::Unit::TestCase
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