Auto save note

This commit is contained in:
Maximilian Friedersdorff 2025-09-30 11:07:54 +01:00
parent a90859e151
commit 33cc62b3fc

View file

@ -37,7 +37,7 @@ var commandBar = new TinyMDE.CommandBar({
'|',
'h1', 'h2',
'|',
'ul', 'ol', {name: "checklist", title: "Check List", action: makeChecklist},
'ul', 'ol',
'|',
'blockquote', 'hr',
'|',
@ -45,9 +45,23 @@ var commandBar = new TinyMDE.CommandBar({
],
});
let editTimeout;
let autoSaveDelay = 2000;
tinyMDE.addEventListener("change", function() {
clearTimeout(editTimeout);
editTimeout = setTimeout(() => {
let form = document.querySelector("form");
let formData = new FormData(form);
fetch("{{.urlSave}}", {
method: "POST",
body: formData,
}).then((data) => {
console.log("Saved Note")
});
}, autoSaveDelay);
});
function makeChecklist(editor) {
editor.wrapSelection("* [ ] ", "")
};
</script>
{{end}}