Module: FGraph::Rails::FGraphTagHelper
- Defined in:
- lib/fgraph/rails/fgraph_tag_helper.rb
Instance Method Summary collapse
- #fgraph_image_options(type) ⇒ Object
- #fgraph_image_tag(id, type = nil, options = {}) ⇒ Object
- #fgraph_javascript_include_tag ⇒ Object
-
#fgraph_javascript_init_tag(options = {}) ⇒ Object
Inititalize XFBML Javascript include and initialization script.
Instance Method Details
#fgraph_image_options(type) ⇒ Object
69 70 71 72 73 74 75 76 77 78 79 80 81 82 |
# File 'lib/fgraph/rails/fgraph_tag_helper.rb', line 69 def (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
63 64 65 66 67 |
# File 'lib/fgraph/rails/fgraph_tag_helper.rb', line 63 def fgraph_image_tag(id, type=nil, ={}) = (type) [:alt] = id['name'] if id.is_a?(Hash) image_tag(fgraph_picture_url(id, type), .merge( || {})) end |
#fgraph_javascript_include_tag ⇒ Object
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 61 |
# File 'lib/fgraph/rails/fgraph_tag_helper.rb', line 23 def fgraph_javascript_init_tag(={}) = { :app_id => FGraph.config['app_id'], :status => true, :cookie => true, :xfbml => true }.merge( || {}) fb_init = "FB.init({appId: '#{[:app_id]}', status: #{[:status]}, cookie: #{[:cookie]}, xfbml: #{[:xfbml]}});" if [:async] %{ <div id="fb-root"></div> <script> window.fbAsyncInit = function() { #{fb_init} if (window.afterFbAsyncInit) { window.afterFbAsyncInit(); } }; (function(d) { var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = "//connect.facebook.net/en_US/all.js"; d.getElementsByTagName('head')[0].appendChild(js); }(document)); </script> } else tag = fgraph_javascript_include_tag tag << %{ <div id="fb-root"></div> <script> #{fb_init} </script> } end end |