From 2a71d4733a904a5e99ebccf6489e68d7231d4586 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Thu, 5 Mar 2020 20:41:33 -0800 Subject: [PATCH] Load preview on page load faster --- amanuensis/resources/editor.js | 11 ++++------- 1 file changed, 4 insertions(+), 7 deletions(-) diff --git a/amanuensis/resources/editor.js b/amanuensis/resources/editor.js index 0cba693..d81db22 100644 --- a/amanuensis/resources/editor.js +++ b/amanuensis/resources/editor.js @@ -21,7 +21,7 @@ window.onload = function() { document.getElementById("editor-content").value = params.article.contents; } - onContentChange(); + onContentChange(0); }; function getArticleObj() { @@ -52,11 +52,11 @@ function update(article) { req.send(JSON.stringify(article)); } -function onContentChange() { +function onContentChange(timeout=2000) { ifNoFurtherChanges(() => { var article = getArticleObj(); update(article); - }); + }, timeout); } window.addEventListener("beforeunload", function(e) { @@ -73,10 +73,7 @@ window.addEventListener("keydown", function(event) { if (String.fromCharCode(event.which).toLowerCase() == 's') { event.preventDefault(); - ifNoFurtherChanges(() => { - var article = getArticleObj(); - update(article); - }, 0); + onContentChange(0); } } }); \ No newline at end of file