From 5db44ab734115651045799a561cd329594ff5c6c Mon Sep 17 00:00:00 2001 From: firm1 Date: Mon, 8 Jun 2020 11:15:30 +0200 Subject: [PATCH] better debounce --- src/js/easymde.js | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/src/js/easymde.js b/src/js/easymde.js index e1b465e..682a9c7 100644 --- a/src/js/easymde.js +++ b/src/js/easymde.js @@ -2037,7 +2037,8 @@ EasyMDE.prototype.render = function (el) { if (options.autosave != undefined && options.autosave.enabled === true) { this.autosave(); // use to load localstorage content this.codemirror.on('change', function () { - setTimeout(function () { + clearTimeout(self._autosave_timeout); + self._autosave_timeout = setTimeout(function () { self.autosave(); }, self.options.autosave.submit_delay || self.options.autosave.delay || 1000); }); @@ -2072,6 +2073,7 @@ function isLocalStorageAvailable() { } EasyMDE.prototype.autosave = function () { + console.log('save'); if (isLocalStorageAvailable()) { var easyMDE = this;