diff options
author | Joshua Peek <josh@joshpeek.com> | 2010-01-30 14:39:41 -0600 |
---|---|---|
committer | Joshua Peek <josh@joshpeek.com> | 2010-01-30 14:39:59 -0600 |
commit | 4f7a85d2c66f100f83e2fe264e1f03bf079f13dc (patch) | |
tree | a9304cf3c3006b472da7e75cf339d6641160e728 /actionpack/lib/action_view/helpers/url_helper.rb | |
parent | ac20f2cea15844b5cc06bdfefbb410fc55ba5caf (diff) | |
download | rails-4f7a85d2c66f100f83e2fe264e1f03bf079f13dc.tar.gz rails-4f7a85d2c66f100f83e2fe264e1f03bf079f13dc.tar.bz2 rails-4f7a85d2c66f100f83e2fe264e1f03bf079f13dc.zip |
Revert "Merge branch 'rails/master' into ujs"
This reverts commit 3aa1ea1ae4baa4a03d03644e798eeb98a4745785, reversing
changes made to 2c12a71378d2146c822acb389b00b866f6420ff5.
Conflicts:
actionpack/lib/action_view/helpers/javascript_helper.rb
actionpack/lib/action_view/helpers/url_helper.rb
actionpack/test/template/url_helper_test.rb
Diffstat (limited to 'actionpack/lib/action_view/helpers/url_helper.rb')
-rw-r--r-- | actionpack/lib/action_view/helpers/url_helper.rb | 45 |
1 files changed, 45 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/url_helper.rb b/actionpack/lib/action_view/helpers/url_helper.rb index 837dca6149..d6bfc6d4c9 100644 --- a/actionpack/lib/action_view/helpers/url_helper.rb +++ b/actionpack/lib/action_view/helpers/url_helper.rb @@ -291,6 +291,9 @@ module ActionView request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) end + if confirm = html_options.delete("confirm") + html_options["onclick"] = "return #{confirm_javascript_function(confirm)};" + end url = options.is_a?(String) ? options : self.url_for(options) name ||= url @@ -548,6 +551,48 @@ module ActionView end private + def convert_options_to_javascript!(html_options, url = '') + confirm = html_options.delete("confirm") + method, href = html_options.delete("method"), html_options['href'] + + if html_options.key?("popup") + ActiveSupport::Deprecation.warn(":popup has been deprecated", caller) + end + + html_options["onclick"] = case + when confirm && method + "if (#{confirm_javascript_function(confirm)}) { #{method_javascript_function(method, url, href)} };return false;" + when confirm + "return #{confirm_javascript_function(confirm)};" + when method + "#{method_javascript_function(method, url, href)}return false;" + else + html_options["onclick"] + end + end + + def confirm_javascript_function(confirm) + "confirm('#{escape_javascript(confirm)}')" + end + + def method_javascript_function(method, url = '', href = nil) + action = (href && url.size > 0) ? "'#{url}'" : 'this.href' + submit_function = + "var f = document.createElement('form'); f.style.display = 'none'; " + + "this.parentNode.appendChild(f); f.method = 'POST'; f.action = #{action};" + + unless method == :post + submit_function << "var m = document.createElement('input'); m.setAttribute('type', 'hidden'); " + submit_function << "m.setAttribute('name', '_method'); m.setAttribute('value', '#{method}'); f.appendChild(m);" + end + + if protect_against_forgery? + submit_function << "var s = document.createElement('input'); s.setAttribute('type', 'hidden'); " + submit_function << "s.setAttribute('name', '#{request_forgery_protection_token}'); s.setAttribute('value', '#{escape_javascript form_authenticity_token}'); f.appendChild(s);" + end + submit_function << "f.submit();" + end + # Processes the +html_options+ hash, converting the boolean # attributes from true/false form into the form required by # HTML/XHTML. (An attribute is considered to be boolean if |