Module: FacebookSocialPlugins::Helper::Script
- Defined in:
- lib/facebook-social_plugins/helper/script.rb
Instance Method Summary collapse
-
#fb_async_init_script(app_id, domain, options = {}) ⇒ Object
app_id - facebook app id, a number/string, fx ‘753632322’ domain - fx www.example.com options - status, cookie, xfbml (true|false) - :channel => ‘channel.html’.
- #fb_channel_script(locale = :en_US) ⇒ Object
-
#fb_login_click_react(options = {:selector => '#fb_login'}, &block) ⇒ Object
can be used inside a js.erb file or similar.
- #fb_login_react(options = {}, &block) ⇒ Object
- #fb_logout_click_react(options = {:selector => '#fb_logout'}, &block) ⇒ Object
- #fb_logout_react(options = {}, &block) ⇒ Object
- #fb_onlogin_react(options = {}, &block) ⇒ Object
- #fb_onlogin_redirect_to(path, options = {}) ⇒ Object
- #fb_onlogout_react(options = {}, &block) ⇒ Object
- #fb_onlogout_redirect_to(path, options = {}) ⇒ Object
- #valid_facebook_id?(id) ⇒ Boolean
Instance Method Details
#fb_async_init_script(app_id, domain, options = {}) ⇒ Object
app_id - facebook app id, a number/string, fx ‘753632322’ domain - fx www.example.com options - status, cookie, xfbml (true|false)
-
:channel => ‘channel.html’
100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 100 def fb_async_init_script app_id, domain, = {} raise ArgumentError, "Not a valid Facebook App ID. It should be a 15 digit number, was: #{app_id}, length=#{app_id.size}" unless valid_facebook_id?(app_id) raise ArgumentError, "No domain name specified" if domain.blank? if [:channel] || [:channel_url] locale = [:locale] || I18n.locale channel = [:channel_url] || "assets/facebook_channel_#{locale}" channelAttrib = "channelUrl : '//#{domain}/#{channel}.html', // Channel File" else channelAttrib = '// No Facebook channel defined (use fx #fb_channel_script)' end %Q{ window.fbAsyncInit = function() { FB.init({ appId : '#{app_id}', // App ID #{channelAttrib} status : #{[:status] || true}, // check login status cookie : #{[:cookie] || true}, // enable cookies to allow the server to access the session xfbml : #{[:xfbml] || true } // parse XFBML }); // Additional initialization code here }; } end |
#fb_channel_script(locale = :en_US) ⇒ Object
131 132 133 134 135 136 137 138 139 140 141 142 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 131 def fb_channel_script locale = :en_US %Q{ (function(d){ var js, id = 'facebook-jssdk'; if (d.getElementById(id)) {return;} js = d.createElement('script'); js.id = id; js.async = true; js.src = '#{all_script(locale)}'; d.getElementsByTagName('head')[0].appendChild(js); }(document)); } end |
#fb_login_click_react(options = {:selector => '#fb_login'}, &block) ⇒ Object
can be used inside a js.erb file or similar
5 6 7 8 9 10 11 12 13 14 15 16 17 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 5 def fb_login_click_react = {:selector => '#fb_login'}, &block selector = [:selector] || '#fb_login' block_content = yield if block on_success = [:on_success] || block_content || '// on success' on_fail = [:on_fail] || '// on failure' script = %Q{$('#{selector}').click(function() { #{fb_login_react(, &block)} return false; } } [:ready] ? wrap_ready(script) : script end |
#fb_login_react(options = {}, &block) ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 19 def fb_login_react = {}, &block block_content = yield if block on_success = [:on_success] || block_content || '// on success' on_fail = [:on_fail] || '// on failure' script = %Q{FB.login(function(response) { if (response.authResponse) { #{on_success} } else { #{on_fail} } }#{ [:scope]}); } [:ready] ? wrap_ready(script) : script end |
#fb_logout_click_react(options = {:selector => '#fb_logout'}, &block) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 36 def fb_logout_click_react = {:selector => '#fb_logout'}, &block selector = [:selector] || '#fb_logout' block_content = yield if block on_done = [:on_done] || block_content || '// on done' script = %Q{$('#{selector}').click(function() { #{fb_logout_react(:on_done => on_done)} return false; } } [:ready] ? wrap_ready(script) : script end |
#fb_logout_react(options = {}, &block) ⇒ Object
48 49 50 51 52 53 54 55 56 57 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 48 def fb_logout_react = {}, &block block_content = yield if block on_done = [:on_done] || block_content || '// on done' script = %Q{FB.logout(function(response) { #{on_done} }); } [:ready] ? wrap_ready(script) : script end |
#fb_onlogin_react(options = {}, &block) ⇒ Object
85 86 87 88 89 90 91 92 93 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 85 def fb_onlogin_react = {}, &block block_content = yield if block reaction = [:reaction] || block_content || ' // on login' script = %Q{FB.Event.subscribe("auth.login", function() { #{reaction} }); } [:ready] ? wrap_ready(script) : script end |
#fb_onlogin_redirect_to(path, options = {}) ⇒ Object
77 78 79 80 81 82 83 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 77 def fb_onlogin_redirect_to path, = {} script = %Q{FB.Event.subscribe("auth.login", function() { window.location = '#{path}' }); } [:ready] ? wrap_ready(script) : script end |
#fb_onlogout_react(options = {}, &block) ⇒ Object
67 68 69 70 71 72 73 74 75 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 67 def fb_onlogout_react = {}, &block block_content = yield if block reaction = [:reaction] || block_content || ' // on logout' script = %Q{FB.Event.subscribe("auth.logout", function() { #{reaction} }); } [:ready] ? wrap_ready(script) : script end |
#fb_onlogout_redirect_to(path, options = {}) ⇒ Object
59 60 61 62 63 64 65 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 59 def fb_onlogout_redirect_to path, = {} script = %Q{FB.Event.subscribe("auth.logout", function() { window.location = '#{path}' }); } [:ready] ? wrap_ready(script) : script end |
#valid_facebook_id?(id) ⇒ Boolean
126 127 128 129 |
# File 'lib/facebook-social_plugins/helper/script.rb', line 126 def valid_facebook_id? id raise ArgumentError, "No Facebook app id specified" if id.blank? id = /\d{15}/ end |