summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--fb_connect.js45
-rw-r--r--fb_connect.module8
2 files changed, 34 insertions, 19 deletions
diff --git a/fb_connect.js b/fb_connect.js
index 0a33d3a..ba3c49b 100644
--- a/fb_connect.js
+++ b/fb_connect.js
@@ -1,31 +1,40 @@
+// Global to keep track of connected state. Better than facebook's 'reloadIfSessionStateChanged' option.
+var fb_connect_fbu = null;
+
+function fb_connect_on_connected(fbu) {
+ //alert("fb_connect_on_connected " + fbu + " settings fbu is " + Drupal.settings.fb_connect.fbu + " fb_connect_fbu is " + fb_connect_fbu);
+ if (fb_connect_fbu === 0) {
+ // We've gone from not connected to connected.
+ window.location.reload();
+ }
+ fb_connect_fbu = fbu;
+}
+
+function fb_connect_on_not_connected() {
+ //alert("fb_connect_on_not_connected ");
+ if (fb_connect_fbu > 0) {
+ // This code will not be reached if fb_connect_logout_onclick (below) calls logoutAndRedirect.
+ //alert("fb_connect_on_not_connected, reloading... ");
+ // We've gone from connected to not connected.
+ window.location.reload();
+ }
+ fb_connect_fbu = 0;
+}
function fb_connect_login_onclick() {
- FB.Facebook.get_sessionState().waitUntilReady(function() {
- var fbu = FB.Facebook.apiClient.get_session() ?
- FB.Facebook.apiClient.get_session().uid :
- 0;
-
- //alert('waitUntilReady callback was called, fbu via javascript is ' + fbu);
- if (fbu) {
- //window.location.reload();
- }
- });
- FB.Connect.requireSession();
+ // This will execute before the user fills out the login form.
+ // More important is fb_connect_on_connected, above.
}
function fb_connect_logout_onclick() {
- FB.Facebook.get_sessionState().waitUntilReady(function() {
- var fbu = FB.Facebook.apiClient.get_session() ?
- FB.Facebook.apiClient.get_session().uid :
- 0;
-
+ FB.ensureInit(function() {
+ //alert('logout and redirect to ' + Drupal.settings.fb_connect.front_url);
FB.Connect.logoutAndRedirect(Drupal.settings.fb_connect.front_url);
});
- FB.Connect.requireSession();
}
-// This function called when fbConnect is initialized
+// This function called after fbConnect is initialized
function fb_connect_init() {
// Use show and hide to degrade gracefully when javascript not enabled.
$('.fb_connect_show').show();
diff --git a/fb_connect.module b/fb_connect.module
index 3e199f5..e89012e 100644
--- a/fb_connect.module
+++ b/fb_connect.module
@@ -84,7 +84,9 @@ function fb_connect_fb($op, $data, &$return) {
if ($data['fb_app']->apikey == $apikey) {
// Init Facebook javascript whenever logged into fbConnect
fb_connect_require_feature('XFBML', $fb_app);
- fb_connect_init_option('reloadIfSessionStateChanged', TRUE, $fb_app);
+ // fb_connect_init_option('reloadIfSessionStateChanged', TRUE, $fb_app);
+ fb_connect_init_option('ifUserConnected', "{fb_connect_on_connected}", $fb_app);
+ fb_connect_init_option('ifUserNotConnected', "{fb_connect_on_not_connected}", $fb_app);
}
}
}
@@ -190,6 +192,10 @@ function fb_connect_footer($is_front) {
$fb_app = $data['fb_app'];
$features = $data['features'];
$options = json_encode($option_data[$fb_app->apikey]);
+ // Hack! What's the way to json_encode a function name?
+ $options = str_replace('"{', '', $options);
+ $options = str_replace('}"', '', $options);
+
// drupal_add_js cannot add external javascript, so we use hook_footer instead.
$output = '<script src="http://static.ak.connect.facebook.com/js/api_lib/v0.4/FeatureLoader.js.php" type="text/javascript"></script>';
$output .= "\n";