20
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
103
104
105
106
107
108
109
110
|
# File 'app/helpers/facebook_rails_helper.rb', line 20
def facebook_initialization options = {}
options[:resize] = :auto unless options.has_key?(:resize)
options[:init] ||= {}
options[:init][:appId] ||= FACEBOOK['app_id'].to_s
options[:init][:status] = true unless options.has_key?(:status)
options[:init][:cookie] = true unless options.has_key?(:cookie)
begin
options[:user_f8id] = current_user_f8id
rescue Exception => e
logger.info "current_user_f8id exception #{ e.to_s }"
end unless options.has_key?(:user_f8id)
onload_resize = %{
var domLoaded = false;
var facebookLoaded = false;
var pageLoaded = false;
function pageLoad() {
if (domLoaded && facebookLoaded) {
if (!pageLoaded) {
pageLoaded = true;
$(document).trigger('page_loaded');
}
sizeToMain();
}
}
function sizeToMain() {
if (domLoaded && facebookLoaded) {
if (typeof adjustCanvasSize == "function") {
adjustCanvasSize();
} else {
var height = $('#main').outerHeight();
if (height > 100) {
FB.Canvas.setSize({ width: 760, height: height + 200 });
}
}
}
}
$(document).ready(function () {
domLoaded = true;
pageLoad();
});
$(window).load(function() {
domLoaded = true; //not neccessary
pageLoad();
});
}
login_status = if options[:user_f8id]
%{
FB.getLoginStatus(function(response) {
if ((response.authResponse && response.authResponse.userID == '#{ options[:user_f8id] }') ||
(response.session && response.session.uid == '#{ options[:user_f8id] }')) {
// logged in and connected user - continue
$(document).trigger('got_facebook_status');
} else {
// no user session available or new user - clear old user's session
window.location.href = window.location.href + (window.location.href.indexOf('?') >= 0 ? '&' : '?') + 'clear_users_session=true';
}
}, true); //force session status reloading
}
else
%{
FB.getLoginStatus(function(response) {
$(document).trigger('got_facebook_status');
});
}
end
%{
<div id="fb-root"></div>
<script type="text/javascript">
#{ onload_resize if options[:resize] == :onload }
window.fbAsyncInit = function() {
FB.init({ #{ options[:init].collect{ |key, value| "#{ key }: #{ value }" }.join(', ') } });
$(document).trigger('facebook_init');
#{ 'facebookLoaded = true; pageLoad();' if options[:resize] == :onload }
#{ 'FB.Canvas.setAutoGrow();' if options[:resize] == :auto }
#{ login_status }
};
(function() {
var e = document.createElement('script'); e.async = true;
e.src = document.location.protocol +
'//connect.facebook.net/#{ get_facebook_locale }/all.js';
document.getElementById('fb-root').appendChild(e);
}());
</script>
}.html_safe
end
|