From 33cc62b3fc7b5f1e2a7775176607b77d25a58155 Mon Sep 17 00:00:00 2001 From: Maximilian Friedersdorff Date: Tue, 30 Sep 2025 11:07:54 +0100 Subject: [PATCH] Auto save note --- internal/conf/templates/edit.tmpl.html | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/internal/conf/templates/edit.tmpl.html b/internal/conf/templates/edit.tmpl.html index b8e9aff..e637b48 100644 --- a/internal/conf/templates/edit.tmpl.html +++ b/internal/conf/templates/edit.tmpl.html @@ -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("* [ ] ", "") -}; {{end}}