mirror of
https://github.com/Ionaru/easy-markdown-editor
synced 2025-07-23 09:54:28 -06:00
fix #181 : allow saving only on change content
This commit is contained in:
parent
9dbb1dbe8a
commit
450bead2d1
@ -8,6 +8,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
|||||||
### Added
|
### Added
|
||||||
- Support for Node.js 14.
|
- Support for Node.js 14.
|
||||||
- Preview without fullscreen (Thanks to [@nick-denry], [#196]).
|
- Preview without fullscreen (Thanks to [@nick-denry], [#196]).
|
||||||
|
- `autosave.saveOnChangeText` option to save the text only when modifying the content of the easymde instance (Thanks to [@firm1], [#181]).
|
||||||
|
|
||||||
### Fixed
|
### Fixed
|
||||||
- Fix cursor displayed position on activity ([#183]).
|
- Fix cursor displayed position on activity ([#183]).
|
||||||
|
@ -121,6 +121,7 @@ easyMDE.value('New input for **EasyMDE**');
|
|||||||
- **enabled**: If set to `true`, saves the text automatically. Defaults to `false`.
|
- **enabled**: If set to `true`, saves the text automatically. Defaults to `false`.
|
||||||
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
|
- **delay**: Delay between saves, in milliseconds. Defaults to `10000` (10s).
|
||||||
- **submit_delay**: Delay before assuming that submit of the form failed and saving the text, in milliseconds. Defaults to `autosave.delay` or `10000` (10s).
|
- **submit_delay**: Delay before assuming that submit of the form failed and saving the text, in milliseconds. Defaults to `autosave.delay` or `10000` (10s).
|
||||||
|
- **saveOnChangeText**: Saves the text only when the content has been changed. Without this parameter, the text will be saved periodically according to the `autosave.delay` parameter.
|
||||||
- **uniqueId**: You must set a unique string identifier so that EasyMDE can autosave. Something that separates this from other instances of EasyMDE elsewhere on your website.
|
- **uniqueId**: You must set a unique string identifier so that EasyMDE can autosave. Something that separates this from other instances of EasyMDE elsewhere on your website.
|
||||||
- **timeFormat**: Set DateTimeFormat. More information see [DateTimeFormat instances](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat). Default `locale: en-US, format: hour:minute`.
|
- **timeFormat**: Set DateTimeFormat. More information see [DateTimeFormat instances](https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/DateTimeFormat). Default `locale: en-US, format: hour:minute`.
|
||||||
- **text**: Set text for autosave.
|
- **text**: Set text for autosave.
|
||||||
@ -210,6 +211,7 @@ var editor = new EasyMDE({
|
|||||||
uniqueId: "MyUniqueID",
|
uniqueId: "MyUniqueID",
|
||||||
delay: 1000,
|
delay: 1000,
|
||||||
submit_delay: 5000,
|
submit_delay: 5000,
|
||||||
|
saveOnChangeText: true,
|
||||||
timeFormat: {
|
timeFormat: {
|
||||||
locale: 'en-US',
|
locale: 'en-US',
|
||||||
format: {
|
format: {
|
||||||
|
@ -2035,7 +2035,16 @@ EasyMDE.prototype.render = function (el) {
|
|||||||
this.gui.statusbar = this.createStatusbar();
|
this.gui.statusbar = this.createStatusbar();
|
||||||
}
|
}
|
||||||
if (options.autosave != undefined && options.autosave.enabled === true) {
|
if (options.autosave != undefined && options.autosave.enabled === true) {
|
||||||
this.autosave();
|
if(this.options.autosave.saveOnChangeText !== undefined && this.options.autosave.saveOnChangeText === true) {
|
||||||
|
this.autosave(false); // use to load localstorage content
|
||||||
|
this.codemirror.on('change', function () {
|
||||||
|
setTimeout(function () {
|
||||||
|
self.autosave(false);
|
||||||
|
}, self.options.autosave.submit_delay || self.options.autosave.delay || 1000);
|
||||||
|
});
|
||||||
|
} else {
|
||||||
|
this.autosave(true);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.gui.sideBySide = this.createSideBySide();
|
this.gui.sideBySide = this.createSideBySide();
|
||||||
@ -2066,7 +2075,7 @@ function isLocalStorageAvailable() {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
EasyMDE.prototype.autosave = function () {
|
EasyMDE.prototype.autosave = function (repeatSaving) {
|
||||||
if (isLocalStorageAvailable()) {
|
if (isLocalStorageAvailable()) {
|
||||||
var easyMDE = this;
|
var easyMDE = this;
|
||||||
|
|
||||||
@ -2084,9 +2093,11 @@ EasyMDE.prototype.autosave = function () {
|
|||||||
localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId);
|
localStorage.removeItem('smde_' + easyMDE.options.autosave.uniqueId);
|
||||||
|
|
||||||
// Restart autosaving in case the submit will be cancelled down the line
|
// Restart autosaving in case the submit will be cancelled down the line
|
||||||
setTimeout(function () {
|
if (repeatSaving === true) {
|
||||||
easyMDE.autosave();
|
setTimeout(function () {
|
||||||
}, easyMDE.options.autosave.submit_delay || easyMDE.options.autosave.delay || 10000);
|
easyMDE.autosave(repeatSaving);
|
||||||
|
}, easyMDE.options.autosave.submit_delay || easyMDE.options.autosave.delay || 10000);
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -2118,9 +2129,11 @@ EasyMDE.prototype.autosave = function () {
|
|||||||
el.innerHTML = save + dd;
|
el.innerHTML = save + dd;
|
||||||
}
|
}
|
||||||
|
|
||||||
this.autosaveTimeoutId = setTimeout(function () {
|
if (repeatSaving === true) {
|
||||||
easyMDE.autosave();
|
this.autosaveTimeoutId = setTimeout(function () {
|
||||||
}, this.options.autosave.delay || 10000);
|
easyMDE.autosave(repeatSaving);
|
||||||
|
}, this.options.autosave.delay || 10000);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
console.log('EasyMDE: localStorage not available, cannot autosave');
|
console.log('EasyMDE: localStorage not available, cannot autosave');
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user