From 74fdc348a333544f8b5940f3779a586703ccd30c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Christian=20M=C3=BCller?= Date: Wed, 28 Oct 2015 14:27:59 +0100 Subject: [PATCH] first version of the draft feature --- resources/public/js/publishing.js | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/resources/public/js/publishing.js b/resources/public/js/publishing.js index 64953e8..5977440 100644 --- a/resources/public/js/publishing.js +++ b/resources/public/js/publishing.js @@ -14,6 +14,10 @@ function md2html(input) { return marked(input); } +function saveDraft() { + localStorage.setItem("draft", $note.value); +} + function onLoad() { $note = $("note"); $action = $("action").value; @@ -33,6 +37,13 @@ function onLoad() { }, delay); }; if ($action == "UPDATE") updatePreview(); + else { + var draft = localStorage.getItem("draft"); + if (draft) { + $note.value = draft; + updatePreview(); + } + } else $note.value = ""; $note.onkeyup = updatePreview; $("publish-button").onclick = function(e) { @@ -43,4 +54,6 @@ function onLoad() { } if (iosDetected) $note.className += " ui-border"; else $note.focus(); + self.onbeforeunload = saveDraft; + setInterval(saveDraft, 60 * 1000) }