Ticket #11537: link_tag_using_delete_javascript_and_target_plus_test.diff
| File link_tag_using_delete_javascript_and_target_plus_test.diff, 3.1 kB (added by thijslangeveld, 4 months ago) |
|---|
-
actionpack/test/template/url_helper_test.rb
old new 202 202 link_to("Destroy", "http://www.example.com", :method => :delete, :href => '#') 203 203 ) 204 204 end 205 206 def test_link_tag_using_delete_javascript_and_target 207 assert_dom_equal( 208 "<a href='http://www.thijslangeveld.nl' onclick=\"var f = document.createElement('form'); f.style.display = 'none'; this.parentNode.appendChild(f); f.method = 'POST'; f.action = this.href;f.target = this.target;var m = document.createElement('input'); m.setAttribute('type', 'hidden'); m.setAttribute('name', '_method'); m.setAttribute('value', 'delete'); f.appendChild(m);f.submit();return false;\" target=\"_top\">Destroy</a>", 209 link_to("Destroy", "http://www.thijslangeveld.nl", :method => :delete, :target => '_top') 210 ) 211 end 205 212 206 213 def test_link_tag_using_post_javascript_and_confirm 207 214 assert_dom_equal( -
actionpack/lib/action_view/helpers/url_helper.rb
old new 442 442 def convert_options_to_javascript!(html_options, url = '') 443 443 confirm, popup = html_options.delete("confirm"), html_options.delete("popup") 444 444 445 method, href = html_options.delete("method"), html_options['href']445 method, href, target = html_options.delete("method"), html_options['href'], html_options['target'] 446 446 447 447 html_options["onclick"] = case 448 448 when popup && method … … 454 454 when confirm 455 455 "return #{confirm_javascript_function(confirm)};" 456 456 when method 457 "#{method_javascript_function(method, url, href )}return false;"457 "#{method_javascript_function(method, url, href, target)}return false;" 458 458 when popup 459 459 popup_javascript_function(popup) + 'return false;' 460 460 else … … 470 470 popup.is_a?(Array) ? "window.open(this.href,'#{popup.first}','#{popup.last}');" : "window.open(this.href);" 471 471 end 472 472 473 def method_javascript_function(method, url = '', href = nil )473 def method_javascript_function(method, url = '', href = nil, target = nil) 474 474 action = (href && url.size > 0) ? "'#{url}'" : 'this.href' 475 475 submit_function = 476 476 "var f = document.createElement('form'); f.style.display = 'none'; " + 477 477 "this.parentNode.appendChild(f); f.method = 'POST'; f.action = #{action};" 478 478 479 if target 480 submit_function << "f.target = this.target;" 481 end 482 479 483 unless method == :post 480 484 submit_function << "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); " 481 485 submit_function << "m.setAttribute('name', '_method'); m.setAttribute('value', '#{method}'); f.appendChild(m);"