Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion src/views/composer.observe.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
29 changes: 29 additions & 0 deletions test/editor_contenteditablemode_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

},

Expand Down Expand Up @@ -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("<b>bold text</b>", 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

Expand Down