Module: FGraph::Rails::FGraphTagHelper

Defined in:
lib/fgraph/rails/fgraph_tag_helper.rb

Instance Method Summary collapse

Instance Method Details

#fgraph_image_options(type) ⇒ Object



68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/fgraph/rails/fgraph_tag_helper.rb', line 68

def fgraph_image_options(type)
  case type
    when 'square'
      {:width => 50, :height => 50}
    when 'small'
      {:width => 50}
    when 'normal'
      {:width => 100}
    when 'large'
      {:width => 200}
    else
      {:width => 50, :height => 50}
  end
end

#fgraph_image_tag(id, type = nil, options = {}) ⇒ Object



62
63
64
65
66
# File 'lib/fgraph/rails/fgraph_tag_helper.rb', line 62

def fgraph_image_tag(id, type=nil, options={})
  default_options = fgraph_image_options(type)
  default_options[:alt] = id['name'] if id.is_a?(Hash)
  image_tag(fgraph_picture_url(id, type), default_options.merge(options || {}))
end

#fgraph_javascript_include_tagObject



4
5
6
# File 'lib/fgraph/rails/fgraph_tag_helper.rb', line 4

def fgraph_javascript_include_tag
  %{<script src="http://connect.facebook.net/en_US/all.js"></script>}
end

#fgraph_javascript_init_tag(options = {}) ⇒ Object

Inititalize XFBML Javascript include and initialization script.

Options

  • app_id - overrride Fgraph.config value.

  • async - asynchronous javascript include & initialization. for other Facebook JS initialization codes please wrap under:

  • status - default: false, will check login status, and auto-login user if they are connected

  • cookie - default: true, auto set cookies

  • xfbml - default: true, auto parse xfbml tags

If async is set to true, the callback function is window.afterFbAsyncInit, e.g.

window.afterFbAsyncInit = function() {
    ....
}


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
55
56
57
58
59
60
# File 'lib/fgraph/rails/fgraph_tag_helper.rb', line 23

def fgraph_javascript_init_tag(options={})
  options = { :app_id => FGraph.config['app_id'], 
    :status => true,
    :cookie => true,
    :xfbml => true
  }.merge(options || {})
  
  fb_init = "FB.init({appId: '#{options[:app_id]}', status: #{options[:status]}, cookie: #{options[:cookie]}, xfbml: #{options[:xfbml]}});"
  
  if options[:async]
    %{
      <div id="fb-root"></div>
      <script>
        window.fbAsyncInit = function() {
          #{fb_init}
          
          if (window.afterFbAsyncInit) {
            window.afterFbAsyncInit();
          }
        };
        (function() {
          var e = document.createElement('script'); e.async = true;
          e.src = document.location.protocol +
            '//connect.facebook.net/en_US/all.js';
          document.getElementById('fb-root').appendChild(e);
        }());
      </script>
    }
  else
    tag = fgraph_javascript_include_tag
    tag << %{
      <div id="fb-root"></div>
      <script>
        #{fb_init}
      </script>
    }
  end
end