From fdf3f78312aa4be35adae76f19eb733ae0502890 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 13 Mar 2014 16:03:46 -0400 Subject: [PATCH] Cleanup widgets to avoid memory leaks --- js/Common.js | 8 +++++--- templates/CRM/common/enableDisableApi.tpl | 4 ++-- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/js/Common.js b/js/Common.js index 45a9e66709..1be50a619d 100644 --- a/js/Common.js +++ b/js/Common.js @@ -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) { $('
' + ts('Loading') + '...
').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) { diff --git a/templates/CRM/common/enableDisableApi.tpl b/templates/CRM/common/enableDisableApi.tpl index d388f07182..7dd9811a00 100644 --- a/templates/CRM/common/enableDisableApi.tpl +++ b/templates/CRM/common/enableDisableApi.tpl @@ -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); }); {/literal} -- 2.25.1