fix setTimeouts
This commit is contained in:
parent
bcf95f41b8
commit
9e7e84a4fc
@ -5,6 +5,7 @@ var tabs = [];
|
||||
let saved = false;
|
||||
let textDirty = false;
|
||||
let saveTimeout = 10000;
|
||||
var to = null;
|
||||
|
||||
document.addEventListener('keyup', function (event) {
|
||||
if (event.key == "F3") {
|
||||
@ -60,7 +61,9 @@ function setHeight() {
|
||||
}
|
||||
});
|
||||
}
|
||||
setTimeout(saveNote, saveTimeout);
|
||||
if (!to) {
|
||||
to = setTimeout(saveNote, saveTimeout);
|
||||
}
|
||||
}
|
||||
|
||||
function search() {
|
||||
@ -133,7 +136,8 @@ function saveNote(event) {
|
||||
}
|
||||
|
||||
if (!textDirty || !validateNote()) {
|
||||
setTimeout(saveNote, saveTimeout);
|
||||
clearTimeout(to);
|
||||
to = setTimeout(saveNote, saveTimeout);
|
||||
return;
|
||||
}
|
||||
|
||||
@ -161,10 +165,14 @@ function saveNote(event) {
|
||||
saved = true;
|
||||
textDirty = false;
|
||||
document.querySelector('#note-header-left h2').classList.remove('dirty');
|
||||
|
||||
if (data.new) {
|
||||
document.querySelector('#noteId').value = data.id;
|
||||
}
|
||||
}
|
||||
})
|
||||
.catch(error => console.log(error))
|
||||
.finally(() => setTimeout(saveNote, saveTimeout));
|
||||
.finally(() => function () { clearTimeout(to); to = setTimeout(saveNote, saveTimeout); });
|
||||
}
|
||||
|
||||
function validateNote() {
|
||||
@ -173,10 +181,8 @@ function validateNote() {
|
||||
const speaker = document.querySelector('#speaker');
|
||||
const series = document.querySelector('#series');
|
||||
const title = document.querySelector('#noteTitle');
|
||||
const id = document.querySelector('#noteId');
|
||||
const psg = document.querySelector('#passage');
|
||||
|
||||
if (!isUuidValid(id.value)) { return false; }
|
||||
if (!title.value.length) { return false; }
|
||||
if (!date.value) { return false; }
|
||||
if (!parseInt(speaker.value)) { return false; }
|
||||
@ -380,6 +386,7 @@ function queryRef(type = null, book = null, input = null) {
|
||||
document.querySelector('#referenceType').value = '';
|
||||
document.querySelector('#referenceBook').value = '';
|
||||
document.querySelector('#referenceBook').style.display = 'none';
|
||||
document.querySelector('#refQuery #search').value = '';
|
||||
closeRef();
|
||||
|
||||
saved = false;
|
||||
|
Loading…
Reference in New Issue
Block a user