Module: ActionView::Helpers::UrlHelper
- Defined in:
- lib/facebooker/rails/facebook_url_helper.rb
Instance Method Summary collapse
-
#add_confirm_to_attributes_with_facebooker!(html_options, confirm, fun = nil) ⇒ Object
Overrides a private method that link_to calls via convert_options_to_javascript! and also, button_to calls directly.
-
#button_to_with_facebooker(name, options = {}, html_options = {}) ⇒ Object
Alters one and only one line of the Rails button_to.
- #convert_options_to_css(options) ⇒ Object
Instance Method Details
#add_confirm_to_attributes_with_facebooker!(html_options, confirm, fun = nil) ⇒ Object
Overrides a private method that link_to calls via convert_options_to_javascript! and also, button_to calls directly. For Facebook, confirm can be a hash of options to stylize the Facebook dialog. Takes :title, :content, :style options. See the Facebook page wiki.developers.facebook.com/index.php/FBJS for valid style formats like “color: ‘black’, background: ‘white’” or like “‘color’,‘black’”.
Examples ==
link_to(“Facebooker”, “rubyforge.org/projects/facebooker”, :confirm=>“Go to Facebooker?”) link_to(“Facebooker”, “rubyforge.org/projects/facebooker”, :confirm=>page says:, :content=>”Go to Facebooker?“) link_to(”Facebooker“, ”rubyforge.org/projects/facebooker“, :confirm=>page says:, :content=>“Go to Facebooker?”, :color=>“pink”)
124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/facebooker/rails/facebook_url_helper.rb', line 124 def add_confirm_to_attributes_with_facebooker!(, confirm, fun = nil) if !respond_to?(:request_comes_from_facebook?) || !request_comes_from_facebook? add_confirm_to_attributes_without_facebooker!(, confirm) else if(confirm.is_a?(Hash)) = confirm.stringify_keys title = .delete("title") || "Please Confirm" content = .delete("content") || "Are you sure?" = .delete("button_confirm") || "Okay" = .delete("button_cancel") || "Cancel" style = .empty? ? "" : () else title,content,style,, = 'Please Confirm', confirm, "", "Okay", "Cancel" end "var dlg = new Dialog().showChoice('#{escape_javascript(title.to_s)}','#{escape_javascript(content.to_s)}','#{escape_javascript(.to_s)}','#{escape_javascript(.to_s)}').setStyle(#{style});"+ "var a=this;dlg.onconfirm = function() { #{fun ? fun : 'document.setLocation(a.getHref());'} };" end end |
#button_to_with_facebooker(name, options = {}, html_options = {}) ⇒ Object
Alters one and only one line of the Rails button_to. See below.
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/facebooker/rails/facebook_url_helper.rb', line 52 def (name, ={}, = {}) if !respond_to?(:request_comes_from_facebook?) || !request_comes_from_facebook? (name,,) else = .stringify_keys convert_boolean_attributes!(, %w( disabled )) method_tag = '' if (method = .delete('method')) && %w{put delete}.include?(method.to_s) method_tag = tag('input', :type => 'hidden', :name => '_method', :value => method.to_s) end form_method = method.to_s == 'get' ? 'get' : 'post' request_token_tag = '' if form_method == 'post' && protect_against_forgery? request_token_tag = tag(:input, :type => "hidden", :name => request_forgery_protection_token.to_s, :value => form_authenticity_token) end if confirm = .delete("confirm") # this line is the only change => html_options["onclick"] = "return #{confirm_javascript_function(confirm)}" ["onclick"] = "#{confirm_javascript_function(confirm, 'a.getForm().submit();')}return false;" end url = .is_a?(String) ? : self.url_for() name ||= url .merge!("type" => "submit", "value" => name) "<form method=\"#{form_method}\" action=\"#{escape_once url}\" class=\"button-to\"><div>" + method_tag + tag("input", ) + request_token_tag + "</div></form>" end end |
#convert_options_to_css(options) ⇒ Object
145 146 147 148 149 150 151 152 |
# File 'lib/facebooker/rails/facebook_url_helper.rb', line 145 def () key_pair = .shift style = "{#{key_pair[0]}: '#{key_pair[1]}'" for key in .keys style << ", #{key}: '#{[key]}'" end style << "}" end |