Index: example/dialog_example.info
===================================================================
RCS file: example/dialog_example.info
diff -N example/dialog_example.info
--- example/dialog_example.info	11 Dec 2009 16:59:23 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,6 +0,0 @@
-; $Id: dialog_example.info,v 1.2 2009/12/11 16:59:23 rz Exp $
-name = Dialog Example
-description = Example implementation of the dialog API.
-core = 7.x
-files[] = dialog_example.module
-dependencies[] = dialog
Index: example/dialog_example.module
===================================================================
RCS file: example/dialog_example.module
diff -N example/dialog_example.module
--- example/dialog_example.module	11 Dec 2009 16:59:23 -0000	1.2
+++ /dev/null	1 Jan 1970 00:00:00 -0000
@@ -1,62 +0,0 @@
-<?php
-// $Id: dialog_example.module,v 1.2 2009/12/11 16:59:23 rz Exp $
-
-/**
- * Implementation of hook_menu().
- */
-function dialog_example_menu() {
-  $items['dialog/example'] = array(
-    'title' => 'Dialog example',
-    'description' => 'A demonstration of the Dialog module.',
-    'page callback' => 'drupal_get_form',
-    'page arguments' => array('dialog_example_page'),
-    'access arguments' => array('access content'),
-  );
-  return $items;
-}
-
-function dialog_example_page() {
-  // 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;
-}
-
-/**
- * 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';
-      }
-    }
-  }
-}
-
-/**
- * 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';
-  }
-  elseif ($form_id == 'user_register' && !empty($form_state['ajax'])) {
-    $form['submit']['#attributes']['class'] = 'ctools-dialog-button';
-  }
-  
-}
-*/
Index: dialog.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dialog/dialog.module,v
retrieving revision 1.2
diff -u -r1.2 dialog.module
--- dialog.module	11 Dec 2009 16:59:23 -0000	1.2
+++ dialog.module	18 Dec 2009 00:51:03 -0000
@@ -1,23 +1,18 @@
 <?php
 // $Id: dialog.module,v 1.2 2009/12/11 16:59:23 rz Exp $
-
 /**
- * Implement hook_page_alter().
+ * @file
+ * The Dialog module provides an API for displaying and interacting with
+ * jQuery UI Dialog modals.
+ *
+ * This API is an integration with Drupal's AJAX Framework.  Using the
+ * ajax "commands" provided, dialogs can be displayed, modified, and
+ * closed.
+ *
+ * @link
+ *   http://api.drupal.org/api/group/ajax/7
+ *   Drupal AJAX framework documentation.
  */
-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);
-  }
-}
 
 /**
  * Implement hook_library().
@@ -42,35 +37,23 @@
 }
 
 /**
- * Implement hook_ajax_render_alter().
+ * Creates a Drupal AJAX command to open the modal with a loading animation.
  */
-function dialog_ajax_render_alter(&$commands) {
-  $loader = array();
-  // Inject additional JavaScript and CSS to the browser's client.
-  $css = drupal_add_css();
-  foreach ($css as $data => $options) {
-    if ($options['type'] == 'file') {
-      $loader['css'][] = base_path() . $options['data'];
-    }
-  }
-  $scripts = drupal_add_js();
-  foreach ($scripts as $data => $options) {
-    if ($options['type'] == 'file') {
-      $loader['js'][] = base_path() . $options['data'];
-    }
-  }
-  if (!empty($loader)) {
-    array_unshift($commands, dialog_command_xlazyloader($loader));
-  }
+function dialog_command_loading() {
+  return array(
+    'command' => 'dialog_loading',
+  );
 }
 
 /**
- * Place HTML within the modal.
+ * Creates a Drupal AJAX command to place HTML within the modal and open it.
  *
- * @param $title
- *   The title of the modal.
- * @param $html
- *   The html to place within the modal.
+ * @param $content
+ *   The HTML content of the modal.
+ * @param $options
+ *   An array of ui.dialog options. See the
+ *   {@link http://jqueryui.com/demos/dialog/ jQuery UI Dialog} documentation
+ *   for available options.
  */
 function dialog_command_display($content, $options = array()) {
   return array(
@@ -81,7 +64,13 @@
 }
 
 /**
- * 
+ * Creates a Drupal AJAX command to close the modal.
+ */
+function dialog_command_close() {
+  return array(
+    'command' => 'dialog_close',
+  );
+}
 
 /**
  * Creates a Drupal AJAX 'xLazyLoader' command.
Index: dialog.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/dialog/dialog.js,v
retrieving revision 1.2
diff -u -r1.2 dialog.js
--- dialog.js	11 Dec 2009 16:59:23 -0000	1.2
+++ dialog.js	18 Dec 2009 00:51:03 -0000
@@ -16,30 +16,6 @@
         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);
   }
 };
 
@@ -89,6 +65,17 @@
 };
 
 /**
+ * Command to close the dialog.
+ */
+Drupal.ajax.prototype.commands.dialog_close = function(ajax, response, status) {
+  var element = Drupal.dialog;
+
+  // Process any other behaviors on the content, and close the dialog box.
+  Drupal.attachBehaviors(element);
+  element.dialog('close');
+};
+
+/**
  * Command to use the xLazyLoader to load additional JavaScript, CSS and images.
  *
  * http://code.google.com/p/ajaxsoft/wiki/xLazyLoader
Index: dialog_examples/dialog_examples.info
===================================================================
RCS file: dialog_examples/dialog_examples.info
diff -N dialog_examples/dialog_examples.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dialog_examples/dialog_examples.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Dialog Examples
+description = Example implementations of the dialog API.
+core = 7.x
+files[] = dialog_examples.module
+dependencies[] = dialog
+dependencies[] = dialog_links
Index: dialog_links/dialog_links.module
===================================================================
RCS file: dialog_links/dialog_links.module
diff -N dialog_links/dialog_links.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dialog_links/dialog_links.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,75 @@
+<?php
+// $Id$
+/**
+ * @file
+ * The Dialog Links module allows links with the 'use-dialog' class
+ * to be opened in a jQuery UI Dialog.
+ */
+
+/**
+ * Implement hook_library_alter().
+ */
+function dialog_links_library_alter(&$libraries, $module) {
+  if ($module == 'dialog') {
+    $path = drupal_get_path('module', 'dialog_links') . '/dialog_links.js';
+    $libraries['dialog']['js'][$path] = array('weight' => JS_DEFAULT + 6);
+  }
+}
+
+/**
+ * Implement hook_page_alter().
+ *
+ * If a request contains the 'dialog' querystring variable, we should render
+ * the page content as a Drupal AJAX Framwork command instead of letting the
+ * page execute as normal.
+ *
+ * TODO: We need to deal with 403s and 404s.
+ */
+function dialog_links_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);
+  }
+}
+
+/**
+ * Implement hook_ajax_render_alter().
+ *
+ * Using the xLazyLoader library and command, load additional css and
+ * javascript into the page.
+ *
+ * TODO: Deal with overloading one theme's css onto another.
+ */
+function dialog_links_ajax_render_alter(&$commands) {
+  if (isset($_GET['dialog'])) {
+    $loader = array();
+    $allowed_media = array('all', 'screen');
+    // Inject additional JavaScript and CSS to the browser's client.
+    $css = drupal_add_css();
+    foreach ($css as $data => $options) {
+      if ($options['type'] == 'file' && in_array($options['media'], $allowed_media)) {
+        $loader['css'][] = base_path() . $options['data'];
+      }
+    }
+    $scripts = drupal_add_js();
+    foreach ($scripts as $data => $options) {
+      if ($options['type'] == 'file') {
+        $loader['js'][] = base_path() . $options['data'];
+      }
+    }
+    if (!empty($loader)) {
+      array_unshift($commands, dialog_command_xlazyloader($loader));
+    }
+
+    // Prepend status messages to the dialog content.
+    $commands[] = ajax_command_prepend('#dialog', theme('status_messages'));
+  }
+}
\ No newline at end of file
Index: dialog_examples/dialog_examples.module
===================================================================
RCS file: dialog_examples/dialog_examples.module
diff -N dialog_examples/dialog_examples.module
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dialog_examples/dialog_examples.module	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,67 @@
+<?php
+// $Id$
+
+/**
+ * Implementation of hook_menu().
+ */
+function dialog_examples_menu() {
+  $items['dialog/examples'] = array(
+    'title' => 'Dialog examples',
+    'description' => 'A demonstration of the Dialog module.',
+    'page callback' => 'drupal_get_form',
+    'page arguments' => array('dialog_examples_page'),
+    'access arguments' => array('access content'),
+  );
+  return $items;
+}
+
+function dialog_examples_page() {
+  // Add the required Dialog JavaScript and CSS.
+  $examples['#attached']['library'] = array(
+    array('dialog', 'dialog'),
+  );
+
+  // Examples for dialog_links module.
+  // Modules may add the 'use-dialog' class to a link to have its content
+  // open in a dialog.
+  $examples['dialog_links']['#prefix'] = '<h3>' . t('Dialog Links') . '</h3>';
+  $examples['dialog_links']['#theme'] = 'item_list';
+  $examples['dialog_links']['#items'] = array(
+    l('Simple test', 'dialog/examples', 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 $examples;
+}
+
+/**
+ * Implement hook_ajax_render_alter().
+ */
+function dialog_examples_ajax_render_alter(&$commands) {
+  // In this example, make the "Simple test" link's dialog box a random size.
+  if (isset($_GET['dialog']) && $_GET['q'] == 'dialog/examples') {
+    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';
+      }
+    }
+  }
+}
+
+/**
+ * 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';
+  }
+  elseif ($form_id == 'user_register' && !empty($form_state['ajax'])) {
+    $form['submit']['#attributes']['class'] = 'ctools-dialog-button';
+  }
+
+}
+*/
Index: dialog_links/dialog_links.js
===================================================================
RCS file: dialog_links/dialog_links.js
diff -N dialog_links/dialog_links.js
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dialog_links/dialog_links.js	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,37 @@
+// $Id: dialog.js,v 1.2 2009/12/11 16:59:23 rz Exp $
+(function ($) {
+
+/**
+ * Searches for links with the 'use-dialog' class and adds a click event 
+ * to open them in a jQuery UI Dialog.
+ */
+
+Drupal.behaviors.dialog_links = {
+  attach: function (context, settings) {
+    // Create the AJAX behavior for each link.
+    $('a.use-dialog', 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);
+  },
+};
+
+})(jQuery);
\ No newline at end of file
Index: dialog_links/dialog_links.info
===================================================================
RCS file: dialog_links/dialog_links.info
diff -N dialog_links/dialog_links.info
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ dialog_links/dialog_links.info	1 Jan 1970 00:00:00 -0000
@@ -0,0 +1,7 @@
+; $Id$
+name = Dialog Links
+description = Allows links to be opened in a jQuery UI Dialog.
+core = 7.x
+package = User interface
+files[] = dialog_links.module
+dependencies[] = dialog
\ No newline at end of file
