Cleanup widgets to avoid memory leaks
authorColeman Watts <coleman@civicrm.org>
Thu, 13 Mar 2014 20:03:46 +0000 (16:03 -0400)
committerColeman Watts <coleman@civicrm.org>
Fri, 14 Mar 2014 13:08:43 +0000 (09:08 -0400)
js/Common.js
templates/CRM/common/enableDisableApi.tpl

index 45a9e66709d07aa3744bacc6b9e6ebbf27a6dd74..1be50a619de212b7fb1ec33dfcf1123f99bf4343 100644 (file)
@@ -832,6 +832,7 @@ CRM.validate = CRM.validate || {
     refresh: function() {
       var that = this;
       var url = this._formatUrl(this.options.url);
+      this.options.crmForm && $('form', this.element).ajaxFormUnbind();
       this.options.block && $('.blockOverlay', this.element).length < 1 && this.element.block();
       $.getJSON(url, function(data) {
         if (typeof(data) != 'object' || typeof(data.content) != 'string') {
@@ -853,6 +854,7 @@ CRM.validate = CRM.validate || {
     },
     _destroy: function() {
       this.element.removeClass('crm-ajax-container');
+      this.options.crmForm && $('form', this.element).ajaxFormUnbind();
       if (this._originalContent !== null) {
         this.element.empty().append(this._originalContent);
       }
@@ -881,7 +883,7 @@ CRM.validate = CRM.validate || {
     if (settings.dialog) {
       $('<div id="'+ settings.target.substring(1) +'"><div class="crm-loading-element">' + ts('Loading') + '...</div></div>').dialog(settings.dialog);
       $(settings.target).on('dialogclose', function() {
-        $(this).dialog('destroy').remove();
+        $(this).crmSnippet('destroy').dialog('destroy').remove();
       });
     }
     if (settings.dialog && !settings.dialog.title) {
@@ -935,9 +937,9 @@ CRM.validate = CRM.validate || {
       }
     });
 
-    var widget = CRM.loadPage(url, settings);
+    var widget = CRM.loadPage(url, settings).off('.crmForm');
 
-    widget.on('crmFormLoad', function(event, data) {
+    widget.on('crmFormLoad.crmForm', function(event, data) {
       var $el = $(this);
       var settings = $el.crmSnippet('option', 'crmForm');
       settings.cancelButton && $(settings.cancelButton, this).click(function(event) {
index d388f07182c170d6469432752e00d6119fb55a89..7dd9811a00da9686bfd766c91e79138e8fc8c58e 100644 (file)
@@ -91,8 +91,8 @@
 
     // Because this is an inline script it may get added to the document more than once, so remove handler before adding
     $('body')
-      .off('click', '.crm-enable-disable')
-      .on('click', '.action-item.crm-enable-disable', enableDisable);
+      .off('.crmEnableDisable')
+      .on('click.crmEnableDisable', '.action-item.crm-enable-disable', enableDisable);
   });
 </script>
 {/literal}