Changeset 4235
- Timestamp:
- 04/19/06 18:08:15 (2 years ago)
- Files:
-
- trunk/actionpack/CHANGELOG (modified) (1 diff)
- trunk/actionpack/lib/action_view/helpers/javascript_helper.rb (modified) (3 diffs)
- trunk/actionpack/test/template/javascript_helper_test.rb (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/actionpack/CHANGELOG
r4216 r4235 1 1 *SVN* 2 3 * Change link_to_function and button_to_function to (optionally) take an update_page block instead of a JavaScript string. Closes #4804. [zraii@comcast.net, Sam Stephenson] 2 4 3 5 * Fixed that remote_form_for can leave out the object parameter and default to the instance variable of the object_name, just like form_for [DHH] trunk/actionpack/lib/action_view/helpers/javascript_helper.rb
r3425 r4235 1 1 require File.dirname(__FILE__) + '/tag_helper' 2 require File.dirname(__FILE__) + '/prototype_helper' 2 3 3 4 module ActionView … … 41 42 JAVASCRIPT_PATH = File.join(File.dirname(__FILE__), 'javascripts') 42 43 end 44 45 include PrototypeHelper 43 46 44 47 # Returns a link that'll trigger a JavaScript +function+ using the 45 48 # onclick handler and return false after the fact. 46 49 # 50 # The +function+ argument can be omitted in favor of an +update_page+ 51 # block, which evaluates to a string when the template is rendered 52 # (instead of making an Ajax request first). 53 # 47 54 # Examples: 48 55 # link_to_function "Greeting", "alert('Hello world!')" 49 # link_to_function(image_tag("delete"), "if confirm('Really?'){ do_delete(); }") 50 def link_to_function(name, function, html_options = {}) 56 # link_to_function(image_tag("delete"), "if (confirm('Really?')) do_delete()") 57 # link_to_function("Show me more", nil, :id => "more_link") do |page| 58 # page[:details].visual_effect :toggle_blind 59 # page[:more_link].replace_html "Show me less" 60 # end 61 def link_to_function(name, function = '', html_options = {}, &block) 51 62 html_options.symbolize_keys! 63 function = update_page(&block) if block_given? 52 64 content_tag( 53 65 "a", name, … … 59 71 end 60 72 61 # Returns a linkthat'll trigger a JavaScript +function+ using the73 # Returns a button that'll trigger a JavaScript +function+ using the 62 74 # onclick handler. 75 # 76 # The +function+ argument can be omitted in favor of an +update_page+ 77 # block, which evaluates to a string when the template is rendered 78 # (instead of making an Ajax request first). 63 79 # 64 80 # Examples: 65 81 # button_to_function "Greeting", "alert('Hello world!')" 66 # button_to_function "Delete", "if confirm('Really?'){ do_delete(); }") 67 def button_to_function(name, function, html_options = {}) 82 # button_to_function "Delete", "if (confirm('Really?')) do_delete()" 83 # button_to_function "Details" do |page| 84 # page[:details].visual_effect :toggle_slide 85 # end 86 def button_to_function(name, function = '', html_options = {}, &block) 68 87 html_options.symbolize_keys! 88 function = update_page(&block) if block_given? 69 89 tag(:input, html_options.merge({ 70 90 :type => "button", :value => name, trunk/actionpack/test/template/javascript_helper_test.rb
r3367 r4235 32 32 end 33 33 34 def test_link_to_function_with_rjs_block 35 html = link_to_function( "Greet me!" ) do |page| 36 page.replace_html 'header', "<h1>Greetings</h1>" 37 end 38 assert_dom_equal %(<a href="#" onclick="Element.update("header", "<h1>Greetings</h1>");; return false;">Greet me!</a>), html 39 end 40 41 34 42 def test_button_to_function 35 43 assert_dom_equal %(<input type="button" onclick="alert('Hello world!');" value="Greeting" />), 36 44 button_to_function("Greeting", "alert('Hello world!')") 37 45 end 46 47 def test_button_to_function_with_rjs_block 48 html = button_to_function( "Greet me!" ) do |page| 49 page.replace_html 'header', "<h1>Greetings</h1>" 50 end 51 assert_dom_equal %(<input type="button" onclick="Element.update("header", "<h1>Greetings</h1>");;" value="Greet me!" />), html 52 end 38 53 end