Index: misc/drupal.js
===================================================================
RCS file: /cvs/drupal/drupal/misc/drupal.js,v
retrieving revision 1.46
diff -u -p -r1.46 drupal.js
--- misc/drupal.js	12 Oct 2008 00:29:09 -0000	1.46
+++ misc/drupal.js	19 Oct 2008 21:52:46 -0000
@@ -14,11 +14,25 @@ Drupal.jsEnabled = document.getElementsB
  * default non-Javascript UIs. Behaviors are registered in the Drupal.behaviors
  * object as follows:
  * @code
- *    Drupal.behaviors.behaviorName = function () {
+ *    Drupal.behaviors.behaviorName = function(context) {
  *      ...
  *    };
  * @endcode
  *
+ * Alternatively, if a behavior must also be detached from a page element,
+ * behaviors are registered as objects with the methods 'attach' and 'detach' as
+ * follows:
+ * @code
+ *    Drupal.behaviors.behaviorName = {
+ *      attach: function(context) {
+ *        ...
+ *      },
+ *      detach: function(context) {
+ *        ...
+ *      }
+ *    };
+ * @endcode
+ *
  * Drupal.attachBehaviors is added below to the jQuery ready event and so
  * runs on initial page load. Developers implementing AHAH/AJAX in their
  * solutions should also call this function after new page content has been
@@ -38,7 +52,41 @@ Drupal.attachBehaviors = function(contex
   context = context || document;
   // Execute all of them.
   jQuery.each(Drupal.behaviors, function() {
-    this(context);
+    if (jQuery.isFunction(this.attach)) {
+    	this.attach(context);
+    }
+    else {
+    	this(context);
+    }
+  });
+};
+
+/**
+ * Detach registered behaviors from a page element.
+ *
+ * Developers implementing AHAH/AJAX in their solutions should call this
+ * function before page content is about to be removed, feeding in an element
+ * to be processed, in order to allow special behaviors to detach from the
+ * content.
+ *
+ * Such implementations should look for the class name that was added in their
+ * corresponding Drupal.behaviors.behaviorName.attach implementation, i.e.
+ * behaviorName-processed, to ensure the behavior is detached only from
+ * previously processed elements.
+ *
+ * @param context
+ *   An element to detach behaviors from. If none is given, the document element
+ *   is used.
+ *
+ * @see Drupal.attachBehaviors
+ */
+Drupal.detachBehaviors = function(context) {
+  context = context || document;
+  // Execute all of them.
+  jQuery.each(Drupal.behaviors, function() {
+    if (jQuery.isFunction(this.detach)) {
+    	this.detach(context);
+    }
   });
 };
 
