From e2d4b4c00e886c2a48f658f9a2d8bcf63acb7e49 Mon Sep 17 00:00:00 2001 From: "Francisco L. Hames Junior" Date: Tue, 23 Feb 2016 13:00:03 -0300 Subject: [PATCH 1/4] addEventListener only accept a string as type --- src/views/composer.observe.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/views/composer.observe.js b/src/views/composer.observe.js index e8203e9..6c5fbc5 100644 --- a/src/views/composer.observe.js +++ b/src/views/composer.observe.js @@ -534,7 +534,7 @@ this.focusState = this.getValue(false, false); // --------- destroy:composer event --------- - container.addEventListener(["DOMNodeRemoved"], handleDomNodeRemoved.bind(this), false); + container.addEventListener("DOMNodeRemoved", 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 From 7b49b86f22ce6deaae33cab18099382e23f44ece Mon Sep 17 00:00:00 2001 From: "Francisco L. Hames Junior" Date: Tue, 23 Feb 2016 13:03:03 -0300 Subject: [PATCH 2/4] DOMNodeRemoved is not fired if parent element is removed --- src/views/composer.observe.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/views/composer.observe.js b/src/views/composer.observe.js index 6c5fbc5..c5a05ed 100644 --- a/src/views/composer.observe.js +++ b/src/views/composer.observe.js @@ -535,6 +535,7 @@ // --------- destroy:composer event --------- 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 From e40c9cb5980efa6de7ede478ff756e23cb957cd6 Mon Sep 17 00:00:00 2001 From: maxxi165 Date: Tue, 28 Feb 2017 16:49:14 +0300 Subject: [PATCH 3/4] test for DomNodeRemoved bug composer destroyed after any html tag in editor deleted, wheh using textarea with contentEditableMode = true --- test/editor_contenteditablemode_test.js | 29 +++++++++++++++++++++++++ 1 file changed, 29 insertions(+) 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 From 539991b557f76011140dd8b931d55e112f94ddf9 Mon Sep 17 00:00:00 2001 From: maxxi165 Date: Tue, 28 Feb 2017 17:09:32 +0300 Subject: [PATCH 4/4] =?UTF-8?q?possible=20fix=20for=20DomNodeRemoved=20bug?= =?UTF-8?q?=20"The=20DOMNodeInserted,=20DOMNodeRemoved,=20and=20DOMSubtree?= =?UTF-8?q?Modified=20mutation=20events=20monitor=20structural=20changes?= =?UTF-8?q?=20to=20an=20element's=20children=E2=80=94either=20elements=20a?= =?UTF-8?q?re=20added=20to=20the=20element's=20children=20or=20they're=20r?= =?UTF-8?q?emoved."?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/views/composer.observe.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/views/composer.observe.js b/src/views/composer.observe.js index 5868847..20844f7 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