Index: popups.js
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/popups/popups.js,v
retrieving revision 1.9.2.17
diff -u -r1.9.2.17 popups.js
--- popups.js	19 Nov 2008 08:35:45 -0000	1.9.2.17
+++ popups.js	20 Nov 2008 00:08:12 -0000
@@ -327,7 +327,7 @@
     data: {destination: Drupal.settings.popups.originalPath}, // Set the destination to the original page.
     beforeSend: Drupal.popups.beforeSend,
     success: function(json) { 
-      Drupal.popups.openContent(json.title, json.messages + json.content, options);
+      Drupal.popups.openContent(json.title, json.messages + json.content, options, element);
     },
     complete: function() {
       $('body').css("cursor", "auto"); // Return the cursor to normal state.      
@@ -376,8 +376,10 @@
  *   HTML to show in the popups.
  * @param options
  *   Hash of options controlling how the popups interacts with the underlying page.
+ * @param element
+ *   A DOM object containing the element that was clicked to initiate the popup.
  */
-Drupal.popups.openContent = function(title, content, options) {
+Drupal.popups.openContent = function(title, content, options, element) {
   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.
@@ -394,7 +396,7 @@
     beforeSubmit: Drupal.popups.beforeSubmit,
     beforeSend: Drupal.popups.beforeSend,
     success: function(response, status) {
-      Drupal.popups.formSuccess(response, options);
+      Drupal.popups.formSuccess(response, options, element);
     },
     error: function() {
       Drupal.popups.message("Bad Response form submission");
@@ -428,8 +430,10 @@
  *     nonModal: bool, does the popups block access to the underlying page.
  *     targetSelectors: hash of jQuery selectors, overrides defaultTargetSelector.
  *     titleSelectors: array of jQuery selectors, where to put the the new title of the page.
+ * @param element
+ *   A DOM object containing the element that was clicked to initiate the popup.
  */
-Drupal.popups.formSuccess = function(data, options) {  
+Drupal.popups.formSuccess = function(data, options, element) {  
   // Determine if we are at an end point, or just moving from one popups to another.
   var done = (data.path === Drupal.settings.popups.originalPath) || (data.path === options.forceReturn);
   if (!done) { // Not done yet, so show new page in new popups.
@@ -437,6 +441,13 @@
     Drupal.popups.openContent(data.title, data.messages + data.content, options);
   }
   else { // Done.
+    if (options.afterSubmit) { // Execute an afterSubmit callback if available.
+      var afterSubmitResult = eval(options.afterSubmit +'(data, options, element)');
+      if (afterSubmitResult == false) {
+        return;
+      }
+    }
+
     if (options.reloadWhenDone) { // Force a non-ajax, complete reload of the page.
       location.reload(); 
     }
