Merge pull request #4677 from colemanw/CRM-15495
[civicrm-core.git] / js / crm.drupal.js
index 7699e6e9d9294498c45d587acaeb4e21e7f3ebc3..4c1849cbc077f98e2750771734a61d1d3a7b2b1a 100644 (file)
@@ -1,12 +1,15 @@
 // http://civicrm.org/licensing
 CRM.$(function($) {
   $(document)
-    .on('crmLoad', function() {
+    .on('crmLoad', function(e) {
       // This is drupal's old-school way of listening for 'load' type events. It has to be called manually.
-      Drupal.attachBehaviors(this);
+      Drupal.attachBehaviors(e.target);
     })
-    .on('crmUnload', function() {
-      Drupal.detachBehaviors(this);
+    .on('crmUnload', function(e) {
+      // This function doesn't exist in D6 so call conditionally
+      if (typeof Drupal.detachBehaviors === 'function') {
+        Drupal.detachBehaviors(e.target);
+      }
     })
     .on('dialogopen', function(e) {
       // D7 hack to get the toolbar out of the way (CRM-15341)