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

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



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/facebooker2/rails/helpers/javascript.rb', line 5

def fb_connect_async_js(app_id=Facebooker2.app_id,options={},&proc)
  opts = Hash.new(true).merge!(options)
  cookie = opts[:cookie]
  status = opts[:status]
  xfbml = opts[:xfbml]
  extra_js = capture(&proc) if block_given?
  js = <<-JAVASCRIPT
  <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
        xfbml  : #{xfbml}  // parse XFBML
      });
      #{extra_js}
    };

    (function() {
      var s = document.createElement('div'); 
      s.setAttribute('id','fb-root'); 
      document.documentElement.getElementsByTagName("HEAD")[0].appendChild(s);
      var e = document.createElement('script');
      e.src = document.location.protocol + '//connect.facebook.net/en_US/all.js';
      e.async = true;
      s.appendChild(e);
    }());
  </script>
JAVASCRIPT
block_given? ? concat(js) : js
end