Module: Facepalm::Rails::Helpers::JavascriptHelper
- Included in:
- Facepalm::Rails::Helpers
- Defined in:
- lib/facepalm/rails/helpers/javascript_helper.rb
Instance Method Summary collapse
-
#fb_connect_js(*args, &block) ⇒ Object
A helper to integrate Facebook Connect to the current page.
Instance Method Details
#fb_connect_js(*args, &block) ⇒ Object
A helper to integrate Facebook Connect to the current page. Generates a JavaScript code that initializes Facebook Javascript client for the current application.
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 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'lib/facepalm/rails/helpers/javascript_helper.rb', line 21 def fb_connect_js(*args, &block) = args. app_id = args.shift || facepalm.app_id .reverse_merge!( :cookie => true, :status => true, :xfbml => true, :frictionless => true, :locale => "en_US" ) extra_js = capture(&block) if block_given? init_js = <<-JAVASCRIPT FB.init({ appId : '#{ app_id }', status : #{ [:status] }, cookie : #{ [:] }, xfbml : #{ [:xfbml] }, frictionlessRequests : #{ [:frictionless] }, channelUrl : '#{ [:channel_url] || 'null' }' }); JAVASCRIPT init_js = "FB._https = true; #{ init_js }" if request.ssl? js_url = "connect.facebook.net/#{[:locale]}/all.js" js_url << "?#{Time.now.change(:min => 0, :sec => 0, :usec => 0).to_i}" if [:weak_cache] if [:async] js = <<-JAVASCRIPT window.fbAsyncInit = function() { #{init_js} #{extra_js} }; (function() { var e = document.createElement('script'); e.src = document.location.protocol + '//#{ js_url }'; e.async = true; document.getElementById('fb-root').appendChild(e); }()); JAVASCRIPT js = <<-CODE <div id="fb-root"></div> <script type="text/javascript">#{ js }</script> CODE else js = <<-CODE <div id="fb-root"></div> <script src="#{ request.protocol }#{ js_url }" type="text/javascript"></script> CODE if [:cache_url] js << <<-CODE <script type="text/javascript"> window.FB || document.write(unescape(\"%3Cscript src='#{ [:cache_url] }' type='text/javascript'%3E%3C/script%3E\")); </script> CODE end js << <<-CODE <script type="text/javascript"> if(typeof FB !== 'undefined'){ #{init_js} #{extra_js} } </script> CODE end js = js.html_safe if block_given? && ::Rails::VERSION::STRING.to_i < 3 concat(js) else js end end |