Index: example/dialog_example.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dialog/example/dialog_example.module,v
retrieving revision 1.1
diff -u -r1.1 dialog_example.module
--- example/dialog_example.module	7 Dec 2009 01:47:59 -0000	1.1
+++ example/dialog_example.module	9 Dec 2009 01:25:00 -0000
@@ -7,102 +7,49 @@
 function dialog_example_menu() {
   $items['dialog/example'] = array(
     'title' => 'Dialog example',
-    'page callback' => 'dialog_example_page',
+    'description' => 'A demonstration of the Dialog module.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('dialog_example_page'),
     'access arguments' => array('access content'),
   );
-  $items['dialog/%ctools_js/example'] = array(
-    'type' => MENU_CALLBACK,
-    'page callback' => 'dialog_example_ajax_callback',
-    'page arguments' => array(1),
-    'access arguments' => array('access content'),
-  );
-
-  $items['user/login/%ctools_js'] = array(
-    'page callback' => 'dialog_login_callback',
-    'page arguments' => array(1, 2),
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
-
-  $items['user/register/%ctools_js'] = array(
-    'page callback' => 'dialog_login_callback',
-    'page arguments' => array(1, 2),
-    'access arguments' => array('access content'),
-    'type' => MENU_CALLBACK,
-  );
-
   return $items;
 }
 
 function dialog_example_page() {
-  dialog_add_js();
-  $links = array();
-  $links[] = l('Simple test', 'dialog/nojs/example', array('attributes' => array('class' => 'ctools-use-dialog')));
-  $links[] = l('User login', 'user/login/nojs', array('attributes' => array('class' => 'ctools-use-dialog')));
-  $links[] = l('User registration', 'user/register/nojs', array('attributes' => array('class' => 'ctools-use-dialog')));
-  return theme('item_list', $links);
-}
-
-function dialog_example_ajax_callback($ajax = FALSE) {
-  if ($ajax) {
-    $options = array(
-      'height' => rand(25, 75) . '%',
-      'width' => rand(25, 75) . '%',
-      'position' => 'center',
-    );
-    dialog_ajax_render('test', dialog_example_page(), $options);
-    return;    
-  }
-
-  return 'hello world';
+  // Add the required Dialog JavaScript and CSS.
+  $links['#attached']['library'] = array(
+    array('dialog', 'dialog'),
+  );
+  // Provide the links.
+  $links['links']['#theme'] = 'item_list';
+  $links['links']['#items'] = array(
+    l('Simple test', 'dialog/example', array('attributes' => array('class' => array('use-dialog')))),
+    l('User login', 'user/login', array('attributes' => array('class' => array('use-dialog')))),
+    l('User registration', 'user/register', array('attributes' => array('class' => array('use-dialog')))),
+  );
+  return $links;
 }
 
 /**
-* Menu callback for our ajax links.
-*/
-function dialog_login_callback($type, $js) {
-  switch ($type) {
-    case 'login':
-      $title = t('Login');
-      $form_id = 'user_login';
-      $msg = 'You are now logged in.';
-      break;
-    case 'register':
-      $title = t('Register');
-      $form_id = 'user_register';
-      $msg = 'You are now registered.';
-      break;
-  }
-
-  if ($js) {
-    ctools_include('ajax');
-    $form_state = array(
-      'ajax' => TRUE,
-      'title' => $title,
-    );
-    $output = dialog_form_wrapper($form_id, $form_state);
-    if (empty($output)) {
-      $output[] = dialog_command_display('Welcome', $msg);
-      $output[] = ctools_ajax_command_redirect('user');
-    }
-    else {
-      foreach ($output as $i => $command) {
-        if ($command['command'] == 'dialog_display') {
-          $output[$i]['options']['height'] = 'auto';
-          $output[$i]['options']['width'] = 600;
-          
-          $output[$i]['options']['position'] = 'center';
-          $output[$i]['options']['resizable'] = FALSE;
-        }
+ * Implement hook_ajax_render_alter().
+ */
+function dialog_example_ajax_render_alter(&$commands) {
+  // In this example, make the "Simple test" link's dialog box a random size.
+  if (isset($_GET['dialog']) && arg(0) == 'dialog' && arg(1) == 'example') {
+    foreach ($commands as &$command) {
+      if ($command['command'] == 'dialog_display') {
+        $command['options']['width'] = rand(25, 75) . '%';
+        $command['options']['height'] = rand(100, 600);
+        $command['options']['position'] = 'center';
       }
     }
-    ctools_ajax_render($output);
-  }
-  else {
-    return drupal_get_form($form_id);
   }
 }
 
+/**
+ * Implement hook_form_alter().
+ *
+ * TODO: Make the form buttons work.
 function dialog_example_form_alter(&$form, $form_state, $form_id) {
   if ($form_id == 'user_login' && !empty($form_state['ajax'])) {
     $form['submit']['#attributes']['class'] = 'ctools-dialog-button';
@@ -111,4 +58,5 @@
     $form['submit']['#attributes']['class'] = 'ctools-dialog-button';
   }
   
-}
\ No newline at end of file
+}
+*/
Index: example/dialog_example.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dialog/example/dialog_example.info,v
retrieving revision 1.1
diff -u -r1.1 dialog_example.info
--- example/dialog_example.info	7 Dec 2009 01:47:59 -0000	1.1
+++ example/dialog_example.info	9 Dec 2009 01:25:00 -0000
@@ -1,5 +1,6 @@
 ; $Id: dialog_example.info,v 1.1 2009/12/07 01:47:59 rz Exp $
 name = Dialog Example
 description = Example implementation of the dialog API.
-core = 6.x
+core = 7.x
+files[] = dialog_example.module
 dependencies[] = dialog
Index: dialog.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dialog/dialog.js,v
retrieving revision 1.1
diff -u -r1.1 dialog.js
--- dialog.js	7 Dec 2009 01:46:11 -0000	1.1
+++ dialog.js	9 Dec 2009 01:25:00 -0000
@@ -9,7 +9,6 @@
 
 (function ($) {
   // Make sure our objects are defined.
-  Drupal.CTools = Drupal.CTools || {};
   Drupal.Dialog = Drupal.Dialog || {};
 
   /**
@@ -84,7 +83,7 @@
    * Generic replacement click handler to open the modal with the destination
    * specified by the href of the link.
    */
-  Drupal.Dialog.clickAjaxButton = function() {
+  /*Drupal.Dialog.clickAjaxButton = function() {
     if ($(this).hasClass('ctools-ajaxing')) {
       return false;
     }
@@ -96,12 +95,12 @@
     }
 
     return false;
-  };
+  };*/
 
   /**
    * Submit responder to do an AJAX submit on all modal forms.
    */
-  Drupal.Dialog.submitAjaxForm = function() {
+  /*Drupal.Dialog.submitAjaxForm = function() {
     if ($(this).hasClass('ctools-ajaxing')) {
       return false;
     }
@@ -148,12 +147,12 @@
       return false;
     }
     return false;
-  };
+  };*/
 
   /**
    * Handle a form button being clicked inside of a dialog.
    */
-  Drupal.Dialog.clickFormButton = function() {
+  /*Drupal.Dialog.clickFormButton = function() {
     if (Drupal.autocompleteSubmit && !Drupal.autocompleteSubmit()) {
       return false;
     }
@@ -170,51 +169,42 @@
     }
     
     return false;
-  };
+  };*/
 
   /**
    * Bind links that will open modals to the appropriate function.
    */
-  Drupal.behaviors.Dialog = function(context) {
-    // Bind links
-    $('a.ctools-use-dialog:not(.ctools-use-dialog-processed)', context)
-      .addClass('ctools-use-dialog-processed')
-      .click(Drupal.Dialog.clickAjaxLink);
-
-    // Bind buttons
-    $('input.ctools-use-dialog:not(.ctools-use-dialog-processed), button.ctools-use-dialog:not(.ctools-use-dialog-processed)', context)
-      .addClass('ctools-use-dialog-processed')
-      .click(Drupal.Dialog.clickAjaxButton);
-
-    if ($(context).attr('id') == 'dialog-main') {
-      // Bind submit links in the modal form.
-      $('form:not(.ctools-use-dialog-processed)', context)
-        .addClass('ctools-use-dialog-processed')
-        .submit(Drupal.Dialog.submitAjaxForm);
-      // add click handlers so that we can tell which button was clicked,
-      // because the AJAX submit does not set the values properly.
-
-      $('input[type="submit"]:not(.ctools-use-dialog-processed), button:not(.ctools-use-dialog-processed)', context)
-        .addClass('ctools-use-dialog-processed')
-        .click(Drupal.Dialog.clickFormButton);
-      
-      var buttons = {}, buttonsMap = {};
-      $('.ctools-dialog-button:not(.ctools-dialog-button-processed)', context)
-        .addClass('ctools-dialog-button-processed')
-        .hide()
-        .each(function() {
-          var text = $(this).is('input') ? $(this).attr('value') : $(this).text();
-          buttonsMap[text] = this;
-          buttons[text] = function(e) {
-            var text = $(e.target).text();
-            var map = $(this).data('dialogButtonsMap');
-            var button = map[text];
-            
-            $(button).click();
-          };
-        });
-      $(context).data('dialogButtonsMap', buttonsMap);
-      $(context).dialog('option', 'buttons', buttons);
+  Drupal.behaviors.Dialog = {
+    attach: function(context, settings) {
+      // Bind links
+      $('a.ctools-use-dialog', context).once('ctools-use-dialog').click(Drupal.Dialog.clickAjaxLink);
+  
+      // Bind buttons
+      //$('input.ctools-use-dialog, button.ctools-use-dialog', context).once('ctools-user-dialog').click(Drupal.Dialog.clickAjaxButton);
+  
+      if ($(context).attr('id') == 'dialog-main') {
+        // Bind submit links in the modal form.
+        //$('form', context).once('ctools-use-dialog').submit(Drupal.Dialog.submitAjaxForm);
+        // add click handlers so that we can tell which button was clicked,
+        // because the AJAX submit does not set the values properly.
+  
+        //$('input[type="submit"], button', context).once('ctools-use-dialog').click(Drupal.Dialog.clickFormButton);
+  
+        var buttons = {}, buttonsMap = {};
+        $('.ctools-dialog-button', context).once().hide().each(function() {
+            var text = $(this).is('input') ? $(this).attr('value') : $(this).text();
+            buttonsMap[text] = this;
+            buttons[text] = function(e) {
+              var text = $(e.target).text();
+              var map = $(this).data('dialogButtonsMap');
+              var button = map[text];
+              
+              $(button).click();
+            };
+          });
+        $(context).data('dialogButtonsMap', buttonsMap);
+        $(context).dialog('option', 'buttons', buttons);
+      }
     }
   };
 
@@ -223,7 +213,7 @@
   /**
    * AJAX responder command to place HTML within the modal.
    */
-  Drupal.CTools.AJAX.commands.dialog_display = function(command) {
+  Drupal.ajax.prototype.commands.dialog_display = function(command) {
     var $el = Drupal.Dialog.dialog;
     $el.html(command.output)
       // remove any previously added buttons
@@ -243,15 +233,15 @@
   /**
    * AJAX responder command to dismiss the modal.
    */
-  Drupal.CTools.AJAX.commands.dialog_dismiss = function(command) {
+  Drupal.ajax.prototype.commands.dialog_dismiss = function(command) {
     Drupal.Dialog.dismiss();
   }
 
   /**
    * Display loading
    */
-  Drupal.CTools.AJAX.commands.dialog_loading = function(command) {
-    Drupal.CTools.AJAX.commands.dialog_display({
+  Drupal.ajax.prototype.commands.dialog_loading = function(command) {
+    Drupal.ajax.prototype.commands.dialog_display({
       output: Drupal.theme('DialogThrobber'),
       title: Drupal.t('Loading...')
     });
Index: dialog.info
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dialog/dialog.info,v
retrieving revision 1.1
diff -u -r1.1 dialog.info
--- dialog.info	7 Dec 2009 01:46:11 -0000	1.1
+++ dialog.info	9 Dec 2009 01:25:00 -0000
@@ -1,9 +1,6 @@
 ; $Id: dialog.info,v 1.1 2009/12/07 01:46:11 rz Exp $
 name = Dialog API
 description = Dialog window API based on jQuery UI Dialog and CTools ajax.
-core = 6.x
+core = 7.x
 package = User interface
-
-dependencies[] = ctools
-dependencies[] = jquery_update
-dependencies[] = jquery_ui
+files[] = dialog.module
Index: dialog.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dialog/dialog.module,v
retrieving revision 1.1
diff -u -r1.1 dialog.module
--- dialog.module	7 Dec 2009 01:46:11 -0000	1.1
+++ dialog.module	9 Dec 2009 01:25:00 -0000
@@ -2,34 +2,42 @@
 // $Id: dialog.module,v 1.1 2009/12/07 01:46:11 rz Exp $
 
 /**
- * Add all the necessary javascript (and css) to be able to display a dialog
- * on the current page.  This must be used on any page that could possibly
- * contain a dialog.  It is safe to call this function repeatedly.
+ * Implement hook_page_alter().
  */
-function dialog_add_js() {
-  // Provide a gate so we only do this once.
-  static $done = FALSE;
-  if ($done) {
-    return;
+function dialog_page_alter(&$page) {
+  if (isset($_GET['dialog'])) {
+    // Construct the contents of the dialog box.
+    $content = render(drupal_set_page_content());
+    $options = array(
+      'title' => drupal_get_title(),
+    );
+
+    // Send over the commands.
+    $commands = array();
+    $commands[] = dialog_command_display($content, $options);
+    ajax_render($commands);
   }
+}
 
-  $settings = array('Dialog' => array(
-    'throbber' => theme('image', ctools_image_path('throbber.gif'), t('Loading...'), t('Loading')),
-  ));
-  
-  drupal_add_js($settings, 'setting');
-  drupal_add_js('misc/jquery.form.js');
-  ctools_add_js('ajax-responder');
-
-  // Add jquery_ui js and css.
-  jquery_ui_add(array('ui.core', 'ui.resizable', 'ui.draggable', 'ui.dialog'));
-  drupal_add_css(JQUERY_UI_PATH .'/themes/base/ui.all.css');
-
-  // And finally, the dialog js.
-  drupal_add_js(drupal_get_path('module', 'dialog') .'/dialog.js');
-
-  // Close the gate.
-  $done = TRUE;
+/**
+ * Implement hook_library().
+ */
+function dialog_library() {
+  $libraries['dialog'] = array(
+    'title' => 'Dialog',
+    'website' => 'http://drupal.org/project/dialog',
+    'version' => '7.x',
+    'js' => array(
+      'misc/ajax.js' => array('weight' => JS_DEFAULT - 5),
+      drupal_get_path('module', 'dialog') . '/dialog2.js' => array('weight' => JS_DEFAULT + 5),
+    ),
+    'dependencies' => array(
+      array('system', 'ui.resizable'),
+      array('system', 'ui.draggable'),
+      array('system', 'ui.dialog'),
+    ),
+  );
+  return $libraries;
 }
 
 /**
@@ -40,18 +48,17 @@
  * @param $html
  *   The html to place within the modal.
  */
-function dialog_command_display($title, $html, $options = array()) {
+function dialog_command_display($content, $options = array()) {
   return array(
     'command' => 'dialog_display',
-    'title' => $title,
-    'output' => $html,
+    'content' => $content,
     'options' => $options,
   );
 }
 
 /**
  * Dismiss the modal.
- */
+ *
 function dialog_command_dismiss() {
   return array(
     'command' => 'dialog_dismiss',
@@ -59,20 +66,11 @@
 }
 
 /**
- * Display loading screen in the modal
- */
-function dialog_command_loading() {
-  return array(
-    'command' => 'dialog_loading',
-  );
-}
-
-/**
  * Perform a simple modal render and immediately exit.
  *
  * This is primarily used for error displays, since usually modals will
  * contain forms.
- */
+ *
 function dialog_ajax_render($title, $output, $options = array()) {
   ctools_include('ajax');
   $commands = array();
@@ -93,7 +91,7 @@
  *   The return will be NULL if the form was successfully submitted unless
  *   you specifically set re_render = TRUE. If ajax is set the
  *   form will never be redirected.
- */
+ *
 function dialog_form_wrapper($form_id, &$form_state) {
   ctools_include('form');
   // This won't override settings already in.
@@ -112,7 +110,7 @@
 
 /**
  * Render a form into an AJAX display.
- */
+ *
 function dialog_form_render($form_state, $output) {
   $title = empty($form_state['title']) ? '' : $form_state['title'];
 
@@ -128,4 +126,4 @@
 
   $commands[] = dialog_command_display($title, $output);
   return $commands;
-}
+}*/
Index: dialog2.js
===================================================================
RCS file: dialog2.js
diff -N dialog2.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dialog2.js	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,91 @@
+// $Id: ajax.js,v 1.6 2009/11/26 03:05:42 webchick Exp $
+(function ($) {
+
+/**
+ * Provides AJAX dialog updating via jQuery $.ajax (Asynchronous JavaScript and XML).
+ */
+
+Drupal.dialog = Drupal.dialog || {};
+
+Drupal.behaviors.dialog = {
+  attach: function (context, settings) {
+    // TODO: There should be a stack of dialog boxes rather then just one.
+    $("body").once("dialog", function() {
+      Drupal.dialog = $('<div id="dialog"></div>').dialog({
+        autoOpen: false,
+        modal: true
+      });
+    });
+
+    // Create the AJAX behavior for each link.
+    $('a.use-dialog, a[href*=admin], a[href*=edit]', context).once('use-dialog', function() {
+      // Tell the server that the call is for a dialog box by appending "dialog".
+      var destination = $(this).attr('href');
+      if (destination.indexOf("?") == -1) {
+        destination += "?dialog";
+      }
+      else {
+        destination += "&dialog";
+      }
+      // Register the AJAX effect.
+      new Drupal.ajax($(this).attr('id'), this, {
+        url: destination,
+        event: "click",
+        type: "GET", // TODO: File bug to allow changing the type of request.
+        error: function(response) {
+          // Even though there's an error, we can retrieve the text.
+          response = Drupal.parseJson(response.responseText)[0];
+          Drupal.ajax.prototype.commands.dialog_display(this, response);
+        }
+      });
+    // When clicking on the link, display a loading screen.
+    }).click(Drupal.ajax.prototype.commands.dialog_loading);
+  }
+};
+
+/**
+ * Provide the HTML to create the throbber.
+ */
+Drupal.theme.prototype.DialogThrobber = function () {
+  var html = '';
+  html += '  <div class="ajax-progress">';
+  html += '    <div class="throbber"></div>';
+  html += '  </div>';
+  return html;
+};
+
+/**
+ * Command to loading screen.
+ */
+Drupal.ajax.prototype.commands.dialog_loading = function(ajax, response, status) {
+  Drupal.ajax.prototype.commands.dialog_display(this, {
+    content: Drupal.theme('DialogThrobber'),
+    title: Drupal.t('Loading...')
+  });
+};
+
+/**
+ * Command to display the dialog.
+ */
+Drupal.ajax.prototype.commands.dialog_display = function(ajax, response, status) {
+  var element = Drupal.dialog;
+  element.dialog('close').html(response.content)
+    // Restore the dialog's default values.
+    .dialog('option', 'buttons', {})
+    .dialog('option', 'width', '600px')
+    .dialog('option', 'height', 'auto')
+    .dialog('option', 'title', response.title);
+
+  // Update the options available with the dialog.
+  if (response.options) {
+    jQuery.each(response.options, function(option, value) {
+      element.dialog('option', option, value);
+    });
+  }
+
+  // Process any other behaviors on the content, and display the dialog box.
+  Drupal.attachBehaviors(element);
+  element.dialog('open');
+};
+
+})(jQuery);
