diff options
author | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-31 04:31:10 +0000 |
---|---|---|
committer | David Heinemeier Hansson <david@loudthinking.com> | 2005-12-31 04:31:10 +0000 |
commit | 987d9dbf31b6bb4fe1547bca17af920aa3d72ac5 (patch) | |
tree | 6adb0224c6c75aa27be7e2502beae25cb89f7746 /actionpack/lib | |
parent | d7487fffe51d03f46800e266e4c972ab55238c89 (diff) | |
download | rails-987d9dbf31b6bb4fe1547bca17af920aa3d72ac5.tar.gz rails-987d9dbf31b6bb4fe1547bca17af920aa3d72ac5.tar.bz2 rails-987d9dbf31b6bb4fe1547bca17af920aa3d72ac5.zip |
Added JavaScriptHelper#button_to_function that works just like JavaScriptHelper#link_to_function but uses a button instead of a href [DHH]
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3367 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_view/helpers/javascript_helper.rb | 14 |
1 files changed, 14 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb index 3be96db001..d61167b264 100644 --- a/actionpack/lib/action_view/helpers/javascript_helper.rb +++ b/actionpack/lib/action_view/helpers/javascript_helper.rb @@ -58,6 +58,20 @@ module ActionView ) end + # Returns a link that'll trigger a JavaScript +function+ using the + # onclick handler. + # + # Examples: + # button_to_function "Greeting", "alert('Hello world!')" + # button_to_function "Delete", "if confirm('Really?'){ do_delete(); }") + def button_to_function(name, function, html_options = {}) + html_options.symbolize_keys! + tag(:input, html_options.merge({ + :type => "button", :value => name, + :onclick => (html_options[:onclick] ? "#{html_options[:onclick]}; " : "") + "#{function};" + })) + end + # Includes the Action Pack JavaScript libraries inside a single <script> # tag. The function first includes prototype.js and then its core extensions, # (determined by filenames starting with "prototype"). |