diff -rNB -U 3 .\fboauth.info ..\fboauth_new\fboauth.info
--- .\fboauth.info	Sat May 05 21:05:56 2012
+++ ..\fboauth_new\fboauth.info	Wed Dec 12 10:32:06 2012
@@ -1,7 +1,7 @@
 name = Facebook OAuth
 description = Allow users to connect with Facebook and query information.
 core = 7.x
-
+scripts[]=fboauth_popup.js
 ; Information added by drupal.org packaging script on 2012-05-05
 version = "7.x-1.5"
 core = "7.x"
diff -rNB -U 3 .\fboauth.install ..\fboauth_new\fboauth.install
--- .\fboauth.install	Sat May 05 20:56:54 2012
+++ ..\fboauth_new\fboauth.install	Wed Dec 12 10:46:51 2012
@@ -20,6 +20,7 @@
 function fboauth_uninstall() {
   variable_del('fboauth_id');
   variable_del('fboauth_secret');
+  variable_del('fboauth_popup_connect');
   variable_del('fboauth_user_email');
   variable_del('fboauth_user_username');
   variable_del('fboauth_user_picture');
diff -rNB -U 3 .\fboauth.module ..\fboauth_new\fboauth.module
--- .\fboauth.module	Sat May 05 20:56:54 2012
+++ ..\fboauth_new\fboauth.module	Wed Dec 12 10:45:59 2012
@@ -3,7 +3,20 @@
 /**
  * Implements hook_menu().
  */
+ 
 function fboauth_menu() {
+  $items['fboauth/connect'] = array(
+      'title' => 'Facebook connect process',
+      'page callback' => 'fboauth_connect',
+      'access callback' => TRUE,
+      'type' => MENU_CALLBACK,
+  );
+  $items['fboauth/popup/connect'] = array(
+      'title' => 'Facebook connect popup',
+      'page callback' => 'fboauth_popup_connect',
+      'access callback' => TRUE,
+      'type' => MENU_CALLBACK,
+  );
   $items['fboauth/%fboauth_action'] = array(
     'title' => 'Facebook connect',
     'page callback' => 'fboauth_action_page',
@@ -36,9 +49,33 @@
     'access arguments' => array(1),
     'file' => 'includes/fboauth.pages.inc',
   );
+  
   return $items;
 }
 
+function fboauth_connect() {
+  // modify uri to point to the relocated menu path of fboauth
+  if (variable_get("fboauth_popup_connect")) {
+    $url = str_replace("connect","popup/connect",$_SERVER['REQUEST_URI']);
+    // output some javascript to close the popup window and redirect the parent Drupal window
+    echo "<script>";
+    if (! isset($_REQUEST['error'])) {
+      echo "window.opener.location='$url';";
+    }
+    echo "setTimeout(function(){ window.close(); }, 500);
+      </script>";
+  }
+  else {
+      module_load_include('inc','fboauth','includes/fboauth.fboauth');
+      return fboauth_action_page(array("name" => "connect"));
+  } 
+  
+}
+function fboauth_popup_connect() {
+  module_load_include('inc','fboauth','includes/fboauth.fboauth');
+  return fboauth_action_page(array("name" => "connect"));
+}
+
 /**
  * Implements hook_theme().
  */
@@ -77,6 +114,7 @@
 function fboauth_block_view($delta) {
   $block = array();
   if (variable_get('fboauth_id', '') && !fboauth_fbid_load()) {
+  
     $block['content'] = fboauth_action_display('connect');
   }
   return $block;
@@ -345,6 +383,9 @@
     ),
     'href' => 'https://www.facebook.com/dialog/oauth',
   );
+  if (variable_get("fboauth_popup_connect",0)) {
+     $return['attributes']['class'] = 'facebook-action-connect facebook-action-popup-connect';
+  }
 
   if ($permissions) {
     $return['query']['scope'] = implode(',', $permissions);
diff -rNB -U 3 .\fboauth_popup.js ..\fboauth_new\fboauth_popup.js
--- .\fboauth_popup.js	Thu Jan 01 01:00:00 1970
+++ ..\fboauth_new\fboauth_popup.js	Wed Dec 12 10:27:35 2012
@@ -0,0 +1,48 @@
+/* jQueryId: lxfacebook.js */
+
+/**
+ * add Drupal behaviors
+ */
+Drupal.behaviors.lxfacebook = {
+  attach: function(context, settings) {
+          //return;
+  /**
+   * modify Facbook Oauth (fboauth) button with class "facebook-action-connect" to open in a popup window, instead
+   * of using the current window.
+   * References:
+   * http://thinkdiff.net/facebook/create-facebook-popup-authentication-window-using-php-and-javascript/
+   * http://developers.facebook.com/docs/authentication/
+   * http://developers.facebook.com/docs/authentication/server-side/
+   * http://developers.facebook.com/docs/reference/dialogs/oauth/
+   */
+  jQuery('.facebook-action-popup-connect').click(function() {
+    var screenX    = typeof window.screenX != 'undefined' ? window.screenX : window.screenLeft,
+      screenY    = typeof window.screenY != 'undefined' ? window.screenY : window.screenTop,
+      outerWidth = typeof window.outerWidth != 'undefined' ? window.outerWidth : document.body.clientWidth,
+      outerHeight = typeof window.outerHeight != 'undefined' ? window.outerHeight : (document.body.clientHeight - 22),
+      width    = 500,
+      height   = 270,
+      left     = parseInt(screenX + ((outerWidth - width) / 2), 10),
+      top      = parseInt(screenY + ((outerHeight - height) / 2.5), 10),
+      features = (
+        'width=' + width
+        + ',height=' + height
+        + ',left=' + left
+        + ',top=' + top 
+      );
+    // The second parameter should not contain spaces or IE shows javascript error. But other browser will not complain.
+    // So here, we use “Login_by_facebook” and not “Login by facebook”.
+    var title = "Login_by_Facebook";
+    var url = jQuery(this).attr("href"); 
+
+    // use 'popup' mode, so that the OAuth dialog is displayed in a form suitable for embedding in a popup window.
+    newwindow = window.open(url+"&display=popup", title, features);
+    if (window.focus) {
+      newwindow.focus();
+    }
+    // don't follow href from anchor tag to prohibit facebook login to open in drupal window
+    return false;
+  });
+  }
+};	
+
diff -rNB -U 3 .\includes\fboauth.fboauth.inc ..\fboauth_new\includes\fboauth.fboauth.inc
--- .\includes\fboauth.fboauth.inc	Sat May 05 20:56:54 2012
+++ ..\fboauth_new\includes\fboauth.fboauth.inc	Wed Dec 12 10:47:05 2012
@@ -117,6 +117,7 @@
       drupal_set_message('Your Facebook e-mail address does not match any existing accounts. If you have an account, you must first log in before you can connect your account to Facebook. Creation of new accounts on this site is disabled.');
     }
   }
+  
 }
 
 /**
@@ -228,6 +229,7 @@
 
   // Allow other modules to manipulate the user information after save.
   foreach (module_implements('fboauth_user_save') as $module) {
+   
     $function = $module . '_fboauth_user_save';
     $function($account, $fbuser);
   }
diff -rNB -U 3 .\includes\fboauth.pages.inc ..\fboauth_new\includes\fboauth.pages.inc
--- .\includes\fboauth.pages.inc	Sat May 05 20:56:54 2012
+++ ..\fboauth_new\includes\fboauth.pages.inc	Wed Dec 12 10:46:34 2012
@@ -28,6 +28,14 @@
     '#default_value' => variable_get('fboauth_secret', ''),
   );
 
+  $form['fboauth_popup_connect'] = array(
+    '#type' => 'checkbox',
+    '#title' => t('Popup login dialog'),
+    '#description' => t('Show Facebook login dialog in popup.'),
+    '#options' => array(0 => t("No"), 1 => t("Yes")),
+    '#default_value' => variable_get('fboauth_popup_connect', 0),
+  );
+
   $form['fboauth_basic_mapping'] = array(
     '#type' => 'fieldset',
     '#title' => t('Basic mapping'),
@@ -141,6 +149,7 @@
 function fboauth_settings_form_submit($form, &$form_state) {
   variable_set('fboauth_id', $form_state['values']['fboauth_id']);
   variable_set('fboauth_secret', $form_state['values']['fboauth_secret']);
+  variable_set('fboauth_popup_connect', $form_state['values']['fboauth_popup_connect']);
 
   variable_set('fboauth_user_email', $form_state['values']['fboauth_user_email']);
   variable_set('fboauth_user_username', $form_state['values']['fboauth_user_username']);
