Skip to content

Commit 604f2c8

Browse files
authored
Merge pull request #31 from adamb70/master
Fix autosave event handler
2 parents e81e1f2 + 04777b4 commit 604f2c8

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

src/js/easymde.js

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1656,11 +1656,23 @@ EasyMDE.prototype.autosave = function () {
16561656
console.log('EasyMDE: You must set a uniqueId to use the autosave feature');
16571657
return;
16581658
}
1659-
1660-
if (easyMDE.element.form != null && easyMDE.element.form != undefined) {
1661-
easyMDE.element.form.addEventListener('submit', function () {
1662-
localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId);
1663-
});
1659+
1660+
if(this.options.autosave.binded !== true) {
1661+
if (easyMDE.element.form != null && easyMDE.element.form != undefined) {
1662+
easyMDE.element.form.addEventListener('submit', function () {
1663+
clearTimeout(easyMDE.autosaveTimeoutId);
1664+
easyMDE.autosaveTimeoutId = undefined;
1665+
1666+
localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId);
1667+
1668+
// Restart autosaving in case the submit will be cancelled down the line
1669+
setTimeout(function() {
1670+
easyMDE.autosave();
1671+
}, easyMDE.options.autosave.delay || 10000);
1672+
});
1673+
}
1674+
1675+
this.options.autosave.binded = true;
16641676
}
16651677

16661678
if (this.options.autosave.loaded !== true) {

0 commit comments

Comments
 (0)