? popups-ajax_load.patch Index: popups.js =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/popups/popups.js,v retrieving revision 1.9.2.18 diff -u -p -r1.9.2.18 popups.js --- popups.js 20 Nov 2008 21:18:57 -0000 1.9.2.18 +++ popups.js 22 Nov 2008 22:52:14 -0000 @@ -334,8 +334,18 @@ Drupal.popups.openPath = function(elemen dataType: 'json', data: params, beforeSend: Drupal.popups.beforeSend, - success: function(json) { - Drupal.popups.openContent(json.title, json.messages + json.content, options); + success: function(json) { + // Call all callbacks. + if (json.__callbacks) { + $.each(json.__callbacks, function(i, callback) { + // The first two arguments are required for work with drupal_alter('ajax_data'). + // The first is the target element to which behaviors should be attached. In this case, + // we send the whole document. + // The second is the JSON data response. + // Any further arguments are custom. In this case, we send the popup's options. + eval(callback)(document, json, options); + }); + } }, complete: function() { $('body').css("cursor", "auto"); // Return the cursor to normal state. @@ -361,7 +371,7 @@ Drupal.popups.openPath = function(elemen dataType: 'json', beforeSend: Drupal.popups.beforeSend, success: function(json) { - Drupal.popups.openContent(json.title, json.messages + json.content, options); + Drupal.popups.openContent(document, json, options); }, error: function() { Drupal.popups.message("Unable to open: " + href); @@ -378,14 +388,17 @@ Drupal.popups.openPath = function(elemen /** * Open content in an ajax popups. * - * @param title - * String title of the popups. - * @param content - * HTML to show in the popups. + * @param target + * Target element to attach behaviors to. Not used here, but included as necessary for + * compliance with drupal_alter('ajax_data'). + * @param data + * Object with title, messages, content, and porentially other properties. * @param options * Hash of options controlling how the popups interacts with the underlying page. */ -Drupal.popups.openContent = function(title, content, options) { +Drupal.popups.openContent = function(target, data, options) { + var title = data.title; + var content = data.messages + data.content; Drupal.popups.open(title, content, null, options.width); // Add behaviors to content in popups. // TODO: d-n-d: need to click to let go of selection. @@ -442,7 +455,7 @@ Drupal.popups.formSuccess = function(dat var done = (data.path === Drupal.settings.popups.originalPath) || (data.path === options.forceReturn); if (!done) { // Not done yet, so show new page in new popups. Drupal.popups.removeLoading(); - Drupal.popups.openContent(data.title, data.messages + data.content, options); + Drupal.popups.openContent(data, options); } else { // Done. if (options.reloadWhenDone) { // Force a non-ajax, complete reload of the page. Index: popups.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/popups/popups.module,v retrieving revision 1.11.2.19 diff -u -p -r1.11.2.19 popups.module --- popups.module 20 Nov 2008 21:18:57 -0000 1.11.2.19 +++ popups.module 22 Nov 2008 22:52:15 -0000 @@ -158,12 +158,16 @@ function popups_form_alter(&$form, $form */ function popups_render_as_json($content) { $path = $_GET['q']; // Get current path from params. - return drupal_json(array( - 'title' => drupal_get_title(), - 'messages' => theme('status_messages'), - 'path' => $path, - 'content' => $content, - )); + $object = new StdClass(); + $object->title = drupal_get_title(); + $object->messages = theme('status_messages'); + $object->path = $path; + $object->content = $content; + $object->__callbacks = array('Drupal.popups.openContent'); + // Allow other modules to alter the data. E.g., ajax_load can register its + // callback here for loading new Javascript and CSS files. + drupal_alter('ajax_data', $object, 'popups'); + drupal_json($object); } /**