? modalframe.patch
Index: flag_friend.modalframe.js
===================================================================
RCS file: flag_friend.modalframe.js
diff -N flag_friend.modalframe.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ flag_friend.modalframe.js	20 Oct 2010 04:17:07 -0000
@@ -0,0 +1,52 @@
+// $Id: $
+
+(function ($) {
+
+Drupal.behaviors.flagFriendModalFrame = function() {
+  $('.ff-modalframe-child:not(.ff-modalframe-processed)').addClass('ff-modalframe-processed').click(function() {
+    var element = this;
+
+    // This is our onSubmit callback that will be called from the child window
+    // when it is requested by a call to modalframe_close_dialog() performed
+    // from server-side submit handlers.
+    function onSubmitCallback(args, statusMessages) {
+      // Display status messages generated during submit processing.
+      if (statusMessages) {
+        $('.ff-modalframe-messages').hide().html(statusMessages).show('slow');
+      }
+
+      if (args && args.message) {
+        // Provide a simple feedback alert deferred a little.
+        setTimeout(function() { alert(args.message); }, 500);
+      }
+      window.scrollTo(0, 0);
+      setTimeout(function() { window.location.reload(); }, 100);
+    }
+
+    // Hide the messages are before opening a new dialog.
+    $('.ff-modalframe-messages').hide('fast');
+
+    // Build modal frame options.
+    var modalOptions = {
+      url: $(element).attr('href'),
+      autoFit: true,
+      onSubmit: onSubmitCallback
+    };
+
+    // Try to obtain the dialog size from the className of the element.
+    var regExp = /^.*ff-modalframe-size\[\s*([0-9]*\s*,\s*[0-9]*)\s*\].*$/;
+    if (typeof element.className == 'string' && regExp.test(element.className)) {
+      var size = element.className.replace(regExp, '$1').split(',');
+      modalOptions.width = parseInt(size[0].replace(/ /g, ''));
+      modalOptions.height = parseInt(size[1].replace(/ /g, ''));
+    }
+
+    // Open the modal frame dialog.
+    Drupal.modalFrame.open(modalOptions);
+
+    // Prevent default action of the link click event.
+    return false;
+  });
+}
+
+})(jQuery);
\ No newline at end of file
Index: flag_friend.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/flag_friend/flag_friend.module,v
retrieving revision 1.3.4.45
diff -u -r1.3.4.45 flag_friend.module
--- flag_friend.module	20 Oct 2010 03:50:14 -0000	1.3.4.45
+++ flag_friend.module	20 Oct 2010 04:17:08 -0000
@@ -62,10 +62,25 @@
  * Implementation of hook_preprocess_flag().
  */
 function flag_friend_preprocess_flag(&$vars) {
-  // this hook preprocesses ALL flag links, so make sure we have ours
+  // This hook preprocesses ALL flag links, so make sure we have ours.
   if ($vars['flag']->name == 'friend') {
     global $user;
     
+    if (module_exists('modalframe')) {
+      // Add the parent js.
+      modalframe_parent_js();
+      
+      // Add or custom js.
+      drupal_add_js(drupal_get_path('module', 'flag_friend') .'/flag_friend.modalframe.js');
+      
+      // Add a few classes.
+      $vars['flag_classes'] .= " ff-modalframe-child";
+      
+      // Allow theme to define the size of this modal frame.
+      $size = theme('flag_friend_modalframe_size');
+      $vars['flag_classes'] .= " ff-modalframe-size[$size]";
+    }
+    
     // Determine what the status in the friend process is.
     $status = flag_friend_determine_friend_status($vars['flag'], $user->uid, $vars['content_id']);
     switch ($status) {
@@ -314,6 +329,10 @@
     $flag = flag_get_flag('friend');
     $content_id = $form['content_id']['#value'];
     $token = isset($_REQUEST['token']) ? $_REQUEST['token'] : '';
+    
+    if (module_exists('modalframe')) {
+      modalframe_child_js();
+    }
 
     switch ($action) {
       case 'flag':
@@ -415,6 +434,11 @@
     // Clean message when user cancel own request.
     flag_friend_message($action, $flag, $content_id, $user->uid);
   }
+  
+  if (module_exists('modalframe')) {
+    // Tell the parent window to close the modal frame dialog.
+    modalframe_close_dialog();
+  }
 }
 
 /**
@@ -609,15 +633,22 @@
     'flag_friend_message_email' => array(
       'arguments' => array('status', 'flag', 'recipient', 'sender'),
     ),
-     'flag_friend_message_form' => array(
+    'flag_friend_message_form' => array(
       'arguments' => array('form'),
     ),
-     'flag_friend_unfriend_form' => array(
+    'flag_friend_unfriend_form' => array(
       'arguments' => array('form'),
     ),
+    'flag_friend_modalframe_size' => array(
+      'arguments' => array(),
+    ),
   );
 }
 
+function theme_flag_friend_modalframe_size() {
+  return '450,250';
+}
+
 /**
  * Implementation of hook_flag_default_flags().
  */
