Module: Facebooker2::Rails::Helpers::Javascript

Included in:
Facebooker2::Rails::Helpers
Defined in:
lib/facebooker2/rails/helpers/javascript.rb

Instance Method Summary (collapse)

Instance Method Details

- (Object) fb_connect_async_js(app_id = Facebooker2.app_id, options = {}, &proc)



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
45
46
47
48
49
50
51
52
53
54
# File 'lib/facebooker2/rails/helpers/javascript.rb', line 14

def fb_connect_async_js(app_id=Facebooker2.app_id,options={},&proc)
  opts = Hash.new.merge!(options)
  cookie = opts[:cookie].nil? ? true : opts[:cookie]
  status = opts[:status].nil? ? true : opts[:status]
  xfbml = opts[:xfbml].nil?   ? true : opts[:xfbml]
  oauth2 = Facebooker2.oauth2 ? true : false
  channel_url = opts[:channel_url]
  lang = opts[:locale] || 'en_US'
  extra_js = capture(&proc) if block_given?
  js = <<-JAVASCRIPT
  <div id="fb-root"></div>
  <script>
    window.fbAsyncInit = function() {
      FB.init({
        appId  : '#{app_id}',
        status : #{status}, // check login status
        cookie : #{cookie}, // enable cookies to allow the server to access the session
        #{"channelUrl : '#{channel_url}', // add channelURL to avoid IE redirect problems" unless channel_url.blank?}
        #{"oauth : true,"  if oauth2}
        xfbml  : #{xfbml}  // parse XFBML
      });
      #{extra_js}
    };

    (function() {
      var e = document.createElement('script'); e.async = true;
      e.src = document.location.protocol + '//connect.facebook.net/#{lang}/all.js';
      document.getElementById('fb-root').appendChild(e);
    }());
  </script>
  JAVASCRIPT
  escaped_js = fb_html_safe(js)
  if block_given? 
   concat(escaped_js)
   #return the empty string, since concat returns the buffer and we don't want double output
   # from klochner
   "" 
  else
   escaped_js
  end
end

- (Object) fb_html_safe(str)



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

def fb_html_safe(str)
  if str.respond_to?(:html_safe)
    str.html_safe
  else
    str
  end
end