CRM-10693 - crmSnippet - restore original content on destroy
authorColeman Watts <coleman@civicrm.org>
Tue, 7 Jan 2014 00:56:07 +0000 (16:56 -0800)
committerColeman Watts <coleman@civicrm.org>
Tue, 7 Jan 2014 00:56:07 +0000 (16:56 -0800)
js/Common.js

index 9493cdcebb7edd31b1397ced6303f0c242dcd8aa..77a7f337d16f00c11d0ed7917f7d3e0ec32f71bd 100644 (file)
@@ -815,6 +815,7 @@ CRM.validate = CRM.validate || {
       block: true,
       crmForm: null
     },
+    _originalContent: null,
     _originalUrl: null,
     isOriginalUrl: function() {
       var 
@@ -890,7 +891,11 @@ CRM.validate = CRM.validate || {
           return;
         }
         data.url = url;
-        that.element.trigger('crmBeforeLoad', data).html(data.content);
+        that.element.trigger('crmBeforeLoad', data);
+        if (that._originalContent === null) {
+          that._originalContent = that.element.contents().detach();
+        }
+        that.element.html(data.content);
         that._handleOrderLinks();
         that.element.trigger('crmLoad', data);
         that.options.crmForm && that.element.trigger('crmFormLoad', data);
@@ -900,6 +905,9 @@ CRM.validate = CRM.validate || {
     },
     _destroy: function() {
       this.element.removeClass('crm-ajax-container');
+      if (this._originalContent !== null) {
+        this.element.empty().append(this._originalContent);
+      }
     }
   });
 
@@ -915,8 +923,7 @@ CRM.validate = CRM.validate || {
         width: '65%',
         height: parseInt($(window).height() * .75),
         close: function() {
-          $(this).dialog('destroy');
-          $(this).remove();
+          $(this).dialog('destroy').remove();
         }
       };
     }