mirror of
https://github.com/zadam/trilium.git
synced 2025-11-03 11:56:01 +01:00
better autosave - only once per 5 seconds with guaranteed save when changing notes
This commit is contained in:
@@ -11,11 +11,25 @@ let tags = {
|
||||
|
||||
let noteChangeDisabled = false;
|
||||
|
||||
let isNoteChanged = false;
|
||||
|
||||
function noteChanged() {
|
||||
if (noteChangeDisabled) {
|
||||
return;
|
||||
}
|
||||
|
||||
isNoteChanged = true;
|
||||
}
|
||||
|
||||
function saveNoteIfChanged(callback) {
|
||||
if (!isNoteChanged) {
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
let note = globalNote;
|
||||
|
||||
let contents = $('#noteDetail').summernote('code');
|
||||
@@ -36,7 +50,13 @@ function noteChanged() {
|
||||
data: JSON.stringify(note),
|
||||
contentType: "application/json",
|
||||
success: function(result) {
|
||||
isNoteChanged = false;
|
||||
|
||||
message("Saved!");
|
||||
|
||||
if (callback) {
|
||||
callback();
|
||||
}
|
||||
},
|
||||
error: function(result) {
|
||||
error("Error saving the note!");
|
||||
@@ -44,6 +64,8 @@ function noteChanged() {
|
||||
});
|
||||
}
|
||||
|
||||
setInterval(saveNoteIfChanged, 5000);
|
||||
|
||||
$(document).ready(function() {
|
||||
$("#noteTitle").on('input', function() {
|
||||
noteChanged();
|
||||
|
||||
Reference in New Issue
Block a user