Skip to content
Open
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
22 changes: 19 additions & 3 deletions src/views/synchronizer.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@
var interval,
that = this,
form = this.textarea.element.form,
formSubmitHandler = null,
formResetHandler = null,
startInterval = function() {
interval = setInterval(function() { that.fromComposerToTextarea(); }, INTERVAL);
},
Expand All @@ -73,10 +75,10 @@
if (form) {
// If the textarea is in a form make sure that after onreset and onsubmit the composer
// has the correct state
wysihtml.dom.observe(form, "submit", function() {
formSubmitHandler = wysihtml.dom.observe(form, "submit", function() {
that.sync(true);
});
wysihtml.dom.observe(form, "reset", function() {
formResetHandler = wysihtml.dom.observe(form, "reset", function() {
setTimeout(function() { that.fromTextareaToComposer(); }, 0);
});
}
Expand All @@ -91,7 +93,21 @@
}
});

this.editor.on("destroy:composer", stopInterval);
function onDestroyComposer() {
stopInterval();

//Cleanup handlers if exist
if (formSubmitHandler != null) {
formSubmitHandler.stop();
formSubmitHandler = null;
}
if (formResetHandler != null) {
formResetHandler.stop();
formResetHandler = null;
}
}

this.editor.on("destroy:composer", onDestroyComposer);
}
});
})(wysihtml);