CRM-15278 - better handling of wysiwyg editors in popups
authorColeman Watts <coleman@civicrm.org>
Wed, 17 Sep 2014 04:07:32 +0000 (00:07 -0400)
committerColeman Watts <coleman@civicrm.org>
Wed, 17 Sep 2014 04:07:32 +0000 (00:07 -0400)
js/crm.ajax.js

index aa6a87095fb366591a85ddd416bd0a64be57a8d2..29b011530e10963382a8b369a5c14b270fe4304d 100644 (file)
           return;
         }
         data.url = url;
-        that.element.trigger('crmBeforeLoad', data).html(data.content);
+        that.element.trigger('crmBeforeLoad', data);
+        that._beforeRemovingContent();
+        that.element.html(data.content);
         that._handleOrderLinks();
         that.element.trigger('crmLoad', data);
         that.options.crmForm && that.element.trigger('crmFormLoad', data);
         that._onFailure();
       });
     },
+    // Perform any cleanup needed before removing/replacing content
+    _beforeRemovingContent: function() {
+      var that = this;
+      if (window.tinyMCE && tinyMCE.editors) {
+        $.each(tinyMCE.editors, function(k) {
+          if ($.contains(that.element[0], this.getElement())) {
+            this.remove();
+          }
+        });
+      }
+      this.options.crmForm && $('form', this.element).ajaxFormUnbind();
+    },
     _destroy: function() {
       this.element.removeClass('crm-ajax-container');
-      this.options.crmForm && $('form', this.element).ajaxFormUnbind();
+      this._beforeRemovingContent();
       if (this._originalContent !== null) {
         this.element.empty().append(this._originalContent);
       }
               this.updateElement && this.updateElement();
             });
           }
+          if (window.tinyMCE && tinyMCE.editors) {
+            $.each(tinyMCE.editors, function() {
+              this.save();
+            });
+          }
         },
         beforeSubmit: function(submission) {
           $.each(formErrors, function() {