| 1 |
|
| 2 |
Drupal.behaviors.fb_connect = function(context) {
|
| 3 |
// Sanity check. Not sure when this can happen, but if it does we can't expect anything to work.
|
| 4 |
if (typeof FB_RequireFeatures == 'undefined') {
|
| 5 |
return;
|
| 6 |
}
|
| 7 |
|
| 8 |
// Tell Facebook to parse any XFBML elements found in the context.
|
| 9 |
FB_RequireFeatures(['XFBML'], function() {
|
| 10 |
$(context).each(function() {
|
| 11 |
if ($(this).html()) {
|
| 12 |
var elem = $(this).get(0);
|
| 13 |
//alert('fb_connect: ' + elem + $(elem).html()); // debug
|
| 14 |
FB.XFBML.Host.parseDomElement(elem);
|
| 15 |
|
| 16 |
// Respect fb_connect classes on new content.
|
| 17 |
$('.fb_connect_show', context).show();
|
| 18 |
$('.fb_connect_hide', context).hide();
|
| 19 |
}
|
| 20 |
});
|
| 21 |
});
|
| 22 |
|
| 23 |
// Support for easy fbml popup markup which degrades when javascript not enabled.
|
| 24 |
// Markup is subject to change. Currently...
|
| 25 |
// <div class=fb_connect_fbml_popup_wrap><a title="POPUP TITLE">LINK MARKUP</a><div class=fb_connect_fbml_popup><fb:SOME FBML>...</fb:SOME FBML><div></div>
|
| 26 |
$('.fb_connect_fbml_popup:not(.fb_connect_fbml_popup-processed)', context).addClass('fb_connect_fbml_popup-processed').prev().each(
|
| 27 |
function() {
|
| 28 |
this.fbml_popup = $(this).next().html();
|
| 29 |
this.fbml_popup_width = parseInt($(this).next().attr('width'));
|
| 30 |
this.fbml_popup_height = parseInt($(this).next().attr('height'));
|
| 31 |
//alert("stored fbml_popup markup: " + this.fbml_popup); // debug
|
| 32 |
$(this).next().remove(); // Remove FBML so facebook does not expand it.
|
| 33 |
})
|
| 34 |
// Handle clicks on the link element.
|
| 35 |
.bind('click',
|
| 36 |
function (e) {
|
| 37 |
//alert('Clicked! Will show ' + this.fbml_popup); // debug
|
| 38 |
popup = new FB.UI.FBMLPopupDialog($(this).attr('title'), this.fbml_popup);
|
| 39 |
if (this.fbml_popup_width) {
|
| 40 |
popup.setContentWidth(this.fbml_popup_width);
|
| 41 |
}
|
| 42 |
if (this.fbml_popup_height) {
|
| 43 |
popup.setContentHeight(this.fbml_popup_height);
|
| 44 |
}
|
| 45 |
popup.set_placement(FB.UI.PopupPlacement.topCenter);
|
| 46 |
popup.show();
|
| 47 |
e.preventDefault();
|
| 48 |
})
|
| 49 |
.parent().show();
|
| 50 |
|
| 51 |
};
|
| 52 |
|
| 53 |
|
| 54 |
// The following functions help us keep track of when a user is logged into Facebook Connect.
|
| 55 |
FB_Connect = function(){};
|
| 56 |
|
| 57 |
// Global to keep track of connected state. Better than facebook's 'reloadIfSessionStateChanged' option.
|
| 58 |
FB_Connect.fbu = null;
|
| 59 |
|
| 60 |
FB_Connect.statusHandle = function(e, data) {
|
| 61 |
if (data.changed) {
|
| 62 |
// Status has changed, user has logged in or logged out.
|
| 63 |
window.location.reload();
|
| 64 |
}
|
| 65 |
};
|
| 66 |
|
| 67 |
FB_Connect.execute_javascript = function() {
|
| 68 |
var url = '/fb_connect/js';
|
| 69 |
$.post(url, null, function(eval_me) {
|
| 70 |
if (eval_me) {
|
| 71 |
eval(eval_me);
|
| 72 |
}
|
| 73 |
});
|
| 74 |
};
|
| 75 |
|
| 76 |
FB_Connect.on_connected = function(fbu) {
|
| 77 |
//alert("FB_Connect.on_connected " + fbu + " settings fbu is " + Drupal.settings.fb_connect.fbu + " FB_Connect.fbu is " + FB_Connect.fbu);
|
| 78 |
var status = {'changed': false, 'fbu': fbu};
|
| 79 |
if (FB_Connect.fbu === 0 || Drupal.settings.fb_connect.fbu != fbu) {
|
| 80 |
status.changed = true;
|
| 81 |
}
|
| 82 |
FB_Connect.fbu = fbu;
|
| 83 |
$.event.trigger('fb_connect_status', status);
|
| 84 |
}
|
| 85 |
|
| 86 |
FB_Connect.on_not_connected = function() {
|
| 87 |
//alert("FB_Connect.on_not_connected, settings fbu is " + Drupal.settings.fb_connect.fbu);
|
| 88 |
var status = {'changed': false, 'fbu': 0};
|
| 89 |
if (FB_Connect.fbu > 0 || Drupal.settings.fb_connect.fbu > 0) {
|
| 90 |
// This code will not be reached if fb_connect_logout_onclick (below) calls logoutAndRedirect.
|
| 91 |
// We've gone from connected to not connected.
|
| 92 |
status.changed = true;
|
| 93 |
}
|
| 94 |
FB_Connect.fbu = 0;
|
| 95 |
$.event.trigger('fb_connect_status', status);
|
| 96 |
}
|
| 97 |
|
| 98 |
FB_Connect.login_onclick = function() {
|
| 99 |
// This will execute before the user fills out the login form.
|
| 100 |
// More important is FB_Connect.on_connected, above.
|
| 101 |
}
|
| 102 |
|
| 103 |
FB_Connect.logout_onclick = function() {
|
| 104 |
FB.ensureInit(function() {
|
| 105 |
//alert('logout and redirect to ' + Drupal.settings.fb_connect.front_url);
|
| 106 |
FB.Connect.logoutAndRedirect(Drupal.settings.fb_connect.front_url);
|
| 107 |
});
|
| 108 |
}
|
| 109 |
|
| 110 |
// This function called after fbConnect is initialized
|
| 111 |
FB_Connect.init = function() {
|
| 112 |
// Respond to connected events
|
| 113 |
$(document).bind('fb_connect_status', FB_Connect.statusHandle);
|
| 114 |
}
|
| 115 |
|