// $Id$ /** * @file * * Javascript specific to facebook connect pages. This means pages * which are not canvas pages, and where fb_connect.module has * initialized the facebook api. The user may or may not have * authorized the app, this javascript will still be loaded. * * Note (!) much of the work done here is deprecated, and moved to fb.js * (where code works equally well on both connect pages and canvas * pages). If your app needs the features here, please report your * use case to our issue queue (http://drupal.org/project/issues/fb), * otherwise these features may go away... */ Drupal.behaviors.fb_connect = function(context) { // Logout of facebook when logging out of drupal. jQuery("a[href^='" + Drupal.settings.basePath + "logout']", context).click(FB_Connect.logoutHandler); // Support markup for dialog boxes. FB_Connect.enablePopups(context); }; FB_Connect = function(){}; // click handler FB_Connect.logoutHandler = function(event) { if (typeof(FB) != 'undefined') { FB.logout(function () { //debugger; }); } }; /** * Move new dialogs to visible part of screen. **/ FB_Connect.centerPopups = function() { var scrollTop = $(window).scrollTop(); $('.fb_dialog:not(.fb_popup_centered)').each(function() { var offset = $(this).offset(); if (offset.left == 0) { // This is some facebook cruft that cannot be centered. } else if (offset.top < 0) { // Not yet visible, don't center. } else if (offset.top < scrollTop) { $(this).css('top', offset.top + scrollTop + 'px'); $(this).addClass('fb_popup_centered'); // Don't move this dialog again. } }); }; FB_Connect.enablePopups = function(context) { // Support for easy fbml popup markup which degrades when javascript not enabled. // Markup is subject to change. Currently... //
LINK MARKUP
...
$('.fb_fbml_popup:not(.fb_fbml_popup-processed)', context).addClass('fb_fbml_popup-processed').prev().each( function() { this.fbml_popup = $(this).next().html(); this.fbml_popup_width = parseInt($(this).next().attr('width')); this.fbml_popup_height = parseInt($(this).next().attr('height')); //console.log("stored fbml_popup markup: " + this.fbml_popup); // debug $(this).next().remove(); // Remove FBML so facebook does not expand it. }) // Handle clicks on the link element. .bind('click', function (e) { var popup; //console.log('Clicked! Will show ' + this.fbml_popup); // debug // http://forum.developers.facebook.net/viewtopic.php?pid=243983 var size = FB.UIServer.Methods["fbml.dialog"].size; if (this.fbml_popup_width) { size.width=this.fbml_popup_width; } if (this.fbml_popup_height) { size.height=this.fbml_popup_height; } FB.UIServer.Methods['fbml.dialog'].size = size; // http://forum.developers.facebook.net/viewtopic.php?id=74743 var markup = this.fbml_popup; if ($(this).attr('title')) { markup = '' + $(this).attr('title') + '' + this.fbml_popup; } var dialog = { method: 'fbml.dialog', // triple-secret undocumented feature. display: 'dialog', fbml: markup, width: this.fbml_popup_width, height: this.fbml_popup_height }; var popup = FB.ui(dialog, function (response) { console.log(response); }); // Start a timer to keep popups centered. // @TODO - avoid starting timer more than once. window.setInterval(FB_Connect.centerPopups, 500); e.preventDefault(); }) .parent().show(); };