From 463fc7110755485ee2644690cb87023357f92f9a Mon Sep 17 00:00:00 2001 From: "Erik St. Martin" Date: Sun, 24 Jan 2010 11:57:38 -0500 Subject: 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 --- .../lib/action_view/helpers/javascript_helper.rb | 41 ++++++++++++++++++++++ 1 file changed, 41 insertions(+) (limited to 'actionpack/lib/action_view/helpers/javascript_helper.rb') 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? '{}' -- cgit v1.2.3