Module: FacebookSocialPlugins::Helper::Script

Defined in:
lib/facebook-social_plugins/helper/script.rb

Instance Method Summary collapse

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
# File 'lib/facebook-social_plugins/helper/script.rb', line 100

def fb_async_init_script app_id, domain, options = {}
%Q{
  window.fbAsyncInit = function() {
 FB.init({
   appId      : '#{app_id}', // App ID
   channelUrl : '//#{domain}/#{options[:channel] || 'assets/facebook_channel'}.html', // Channel File
   status     : #{options[:status] || true}, // check login status
   cookie     : #{options[:cookie] || true}, // enable cookies to allow the server to access the session
   xfbml      : #{options[:xfbml] || true }  // parse XFBML
 });

 // Additional initialization code here
  };
}
end

#fb_channel_script(locale = :en_US) ⇒ Object



116
117
118
119
120
121
122
123
124
125
# File 'lib/facebook-social_plugins/helper/script.rb', line 116

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  options = {:selector => '#fb_login'}, &block
	selector = options[:selector] || '#fb_login'
	block_content = yield if block
	on_success = options[:on_success] || block_content || '// on success'
	on_fail = options[:on_fail] || '// on failure'

	script = %Q{$('#{selector}').click(function() { 
#{(options, &block)}
return false;
}
}				
	options[: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  options = {}, &block
	block_content = yield if block
	on_success = options[:on_success] || block_content || '// on success'
	on_fail = options[:on_fail] || '// on failure'

	script = %Q{FB.login(function(response) { 
if (response.authResponse) {
	#{on_success}
} else {
	#{on_fail}
}			
	}#{scope_permissions options[:scope]}); 
}
	options[: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 options = {:selector => '#fb_logout'}, &block
	selector 	= options[:selector] || '#fb_logout'
	block_content = yield if block
	on_done 	= options[:on_done] || block_content || '// on done'
	script = %Q{$('#{selector}').click(function() { 
#{fb_logout_react(:on_done => on_done)}
return false;
}
}				
	options[: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 options = {}, &block
	block_content = yield if block
	on_done = options[:on_done] || block_content || '// on done'

	script = %Q{FB.logout(function(response) { 
#{on_done}
	});
}
	options[: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 options = {}, &block
	block_content = yield if block
	reaction = options[:reaction] || block_content || ' // on login'
	script = %Q{FB.Event.subscribe("auth.login", function() { 
#{reaction} 
	});
}
	options[: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, options = {}
	script = %Q{FB.Event.subscribe("auth.login", function() { 
	window.location = '#{path}' 
	}); 
}
	options[: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 options = {}, &block
	block_content = yield if block
	reaction = options[:reaction] || block_content || ' // on logout'
	script = %Q{FB.Event.subscribe("auth.logout", function() { 
#{reaction} 
	});
}
	options[: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, options = {}
	script = %Q{FB.Event.subscribe("auth.logout", function() { 
	window.location = '#{path}' 
	}); 
}
	options[:ready] ? wrap_ready(script) : script
end