Module: Facebooker::Rails::Helpers::FbConnect

Included in:
Facebooker::Rails::Helpers
Defined in:
lib/facebooker/rails/helpers/fb_connect.rb

Instance Method Summary collapse

Instance Method Details

#fb_connect_javascript_tagObject



6
7
8
9
10
11
12
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 6

def fb_connect_javascript_tag
  if request.ssl?
    javascript_include_tag "https://www.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
  else
    javascript_include_tag "http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php"
  end
end

#fb_login_and_redirect(url, options = {}) ⇒ Object



72
73
74
75
76
77
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 72

def (url, options = {})
  js = update_page do |page|
    page.redirect_to url
  end
  ("fb:login-button",nil,options.merge(:onlogin=>js))
end

#fb_login_button(*args) ⇒ Object

Render an <fb:login-button> element

Examples

<%= fb_login_button%>

> <fb:login-button></fb:login-button>

Specifying a javascript callback

<%= fb_login_button ‘update_something();’%>

> <fb:login-button onlogin=‘update_something();’></fb:login-button>

Adding options See: wiki.developers.facebook.com/index.php/Fb:login-button

<%= fb_login_button ‘update_something();’, :size => :small, :background => :dark%>

> <fb:login-button background=‘dark’ onlogin=‘update_something();’ size=‘small’></fb:login-button>



63
64
65
66
67
68
69
70
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 63

def (*args)

  callback = args.first
  options = args[1] || {}
  options.merge!(:onlogin=>callback)if callback

  ("fb:login-button",nil, options)
end


83
84
85
86
87
88
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 83

def fb_logout_link(text,url,*args)
  js = update_page do |page|
    page.call "FB.Connect.logoutAndRedirect",url
  end
  link_to_function text, js, *args
end

#fb_unconnected_friends_countObject



79
80
81
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 79

def fb_unconnected_friends_count
   "fb:unconnected-friends-count",nil
end

#fb_user_action(action, user_message = "", prompt = "", callback = nil) ⇒ Object



90
91
92
93
94
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 90

def fb_user_action(action, user_message = "", prompt = "", callback = nil)
  update_page do |page|
    page.call "FB.Connect.showFeedDialog",action.template_id,action.data,action.target_ids,action.body_general,nil,page.literal("FB.RequireConnect.promptConnect"),callback,prompt,user_message
  end
end

#init_fb_connect(*required_features, &proc) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/facebooker/rails/helpers/fb_connect.rb', line 14

def init_fb_connect(*required_features,&proc)
  additions = ""
  if block_given?
    additions = capture(&proc)
  end

  options = {:js => :prototype}
  if required_features.last.is_a?(Hash)
    options.merge!(required_features.pop.symbolize_keys)
  end

  init_string = "FB.Facebook.init('#{Facebooker.api_key}','/xd_receiver.html');"
  unless required_features.blank?
     init_string = <<-FBML
     #{case options[:js]
       when :jquery then "$(document).ready("
       else "Element.observe(window,'load',"
       end} function() {
        FB_RequireFeatures(#{required_features.to_json}, function() {
          #{init_string}
          #{additions}
        });
      });
      FBML
  end
  if block_given? && block_is_within_action_view?(proc)
    concat(javascript_tag(init_string), proc.binding)
  else
    javascript_tag init_string
  end
end