aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_view/helpers/javascript_helper.rb
diff options
context:
space:
mode:
authorErik St. Martin <alakriti@gmail.com>2010-01-24 11:57:38 -0500
committerStefan Penner <stefan.penner@gmail.com>2010-01-27 12:44:33 -0600
commit463fc7110755485ee2644690cb87023357f92f9a (patch)
tree6c014a65a8265795cd1c4723f6d1c8cc66f72acf /actionpack/lib/action_view/helpers/javascript_helper.rb
parentc3baf8b767bdfb27b90b2120f9512d9697e5e932 (diff)
downloadrails-463fc7110755485ee2644690cb87023357f92f9a.tar.gz
rails-463fc7110755485ee2644690cb87023357f92f9a.tar.bz2
rails-463fc7110755485ee2644690cb87023357f92f9a.zip
making non remote versions of link_to, button_to, submit_tag and image_submit_tag output data attributes for things like :confirm, :method, :popup, and :disable_with
Diffstat (limited to 'actionpack/lib/action_view/helpers/javascript_helper.rb')
-rw-r--r--actionpack/lib/action_view/helpers/javascript_helper.rb41
1 files changed, 41 insertions, 0 deletions
diff --git a/actionpack/lib/action_view/helpers/javascript_helper.rb b/actionpack/lib/action_view/helpers/javascript_helper.rb
index adb35ccfa2..ba6aefca26 100644
--- a/actionpack/lib/action_view/helpers/javascript_helper.rb
+++ b/actionpack/lib/action_view/helpers/javascript_helper.rb
@@ -188,6 +188,47 @@ module ActionView
end
protected
+ def convert_options_to_javascript!(html_options, url = '')
+ confirm, popup = html_options.delete("confirm"), html_options.delete("popup")
+
+ method, href = html_options.delete("method"), html_options['href']
+
+ if popup && method
+ raise ActionView::ActionViewError, "You can't use :popup and :method in the same link"
+ elsif confirm && popup
+ add_confirm_to_attributes!(html_options, confirm)
+ html_options["data-popup"] = popup_attributes(popup)
+ elsif confirm && method
+ add_confirm_to_attributes!(html_options, confirm)
+ add_method_to_attributes!(html_options, method, url)
+ elsif confirm
+ add_confirm_to_attributes!(html_options, confirm)
+ elsif method
+ add_method_to_attributes!(html_options, method, url)
+ elsif popup
+ html_options["data-popup"] = popup_attributes(popup)
+ end
+ end
+
+ def add_confirm_to_attributes!(html_options, confirm)
+ html_options["data-confirm"] = confirm if confirm
+ end
+
+ def add_method_to_attributes!(html_options, method, url = nil)
+ html_options["data-method"] = method
+ if url.size > 0
+ html_options["data-url"] = url
+ end
+ end
+
+ def add_disable_with_to_attributes!(html_options, disable_with)
+ html_options["data-disable-with"] = disable_with if disable_with
+ end
+
+ def popup_attributes(popup)
+ popup.is_a?(Array) ? "{title: '#{popup.first}', options: '#{popup.last}'}" : "true"
+ end
+
def options_for_javascript(options)
if options.empty?
'{}'