diff --git a/src/views/composer.observe.js b/src/views/composer.observe.js index 5868847..7e6bd99 100644 --- a/src/views/composer.observe.js +++ b/src/views/composer.observe.js @@ -335,10 +335,12 @@ }; var handleDomNodeRemoved = function(event) { + if (event.target == this.element) { if (this.domNodeRemovedInterval) { clearInterval(domNodeRemovedInterval); } this.parent.fire("destroy:composer"); + } }; // Listens to "drop", "paste", "mouseup", "focus", "keyup" events and fires @@ -596,7 +598,8 @@ this.actions = actions; // --------- destroy:composer event --------- - container.addEventListener(["DOMNodeRemoved"], handleDomNodeRemoved.bind(this), false); + container.addEventListener("DOMNodeRemoved", handleDomNodeRemoved.bind(this), false); + container.addEventListener("DOMNodeRemovedFromDocument", handleDomNodeRemoved.bind(this), false); // DOMNodeRemoved event is not supported in IE 8 // TODO: try to figure out a polyfill style fix, so it could be transferred to polyfills and removed if ie8 is not needed diff --git a/test/editor_contenteditablemode_test.js b/test/editor_contenteditablemode_test.js index 779da41..240cf11 100644 --- a/test/editor_contenteditablemode_test.js +++ b/test/editor_contenteditablemode_test.js @@ -13,9 +13,15 @@ if (wysihtml.browser.supported()) { this.editableArea.title = "Please enter your foo"; this.editableArea.innerHTML = "hey tiff, what's up?"; + this.textareaElement = document.createElement("textarea"); + this.textareaElement.id = "wysihtml-test-textarea"; + this.textareaElement.title = "Please enter your foo"; + this.textareaElement.value = "hey tiff, what's up?"; + this.originalBodyClassName = document.body.className; document.body.appendChild(this.editableArea); + document.body.appendChild(this.textareaElement); }, @@ -449,6 +455,29 @@ if (wysihtml.browser.supported()) { }.bind(this)); }); + asyncTest("DomNodeRemoved", function() { + expect(1); + + var that = this, + editor = new wysihtml.Editor(this.textareaElement, { + contentEditableMode: true, + parserRules: { + tags: { + b: true + } + } + }); + + editor.on("load", function () { + editor.setValue("bold text", true); + + setTimeout(function () { + equal(that.textareaElement.value, editor.composer.getValue(false, false), "Composer still sync"); + start(); + }, 800); + }); + }); + /* // TODO: needs logic rethink of terms and conditions