From f9ec3c66ff1305ca0647454d27793ac5365f7f4a Mon Sep 17 00:00:00 2001 From: Andrew Manning Date: Sun, 8 Apr 2018 19:44:21 -0400 Subject: Added feature setting for auto-save, defaulting to enabled. --- view/js/main.js | 20 +++++++++------ view/tpl/comment_item.tpl | 3 +++ view/tpl/jot-header.tpl | 62 ++++++++++++++++++++++++++--------------------- 3 files changed, 51 insertions(+), 34 deletions(-) (limited to 'view') diff --git a/view/js/main.js b/view/js/main.js index d09615f3c..c3c2c850f 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -167,9 +167,13 @@ function handle_comment_form(e) { $('#' + commentElm).attr('tabindex','9'); $('#' + submitElm).attr('tabindex','10'); - var commentBody = localStorage.getItem("comment_body"); - if(commentBody && $('#' + commentElm).val() === '') { - $('#' + commentElm).val(commentBody); + if(auto_save_draft) { + var commentBody = localStorage.getItem("comment_body"); + if(commentBody && $('#' + commentElm).val() === '') { + $('#' + commentElm).val(commentBody); + } + } else { + localStorage.removeItem("comment_body"); } form.find(':not(:visible)').show(); @@ -207,10 +211,12 @@ function handle_comment_form(e) { },10000); }); - function commentSaveChanges(isFinal = false, type) { - localStorage.setItem("comment_body", $('#' + emptyCommentElm).val()); - if( !isFinal) { - commentSaveTimer = setTimeout(commentSaveChanges,10000); + function commentSaveChanges(isFinal = false) { + if(auto_save_draft) { + localStorage.setItem("comment_body", $('#' + emptyCommentElm).val()); + if( !isFinal) { + commentSaveTimer = setTimeout(commentSaveChanges,10000); + } } } } diff --git a/view/tpl/comment_item.tpl b/view/tpl/comment_item.tpl index 3b51971ec..23594677c 100755 --- a/view/tpl/comment_item.tpl +++ b/view/tpl/comment_item.tpl @@ -1,3 +1,6 @@ + {{if $threaded}}
{{else}} diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index 2b4284ade..7af344681 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -580,37 +580,45 @@ $( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-del }); function postSaveChanges(isFinal = false, type) { - localStorage.setItem("post_title", $("#jot-title").val()); - localStorage.setItem("post_body", $("#profile-jot-text").val()); - localStorage.setItem("post_category", $("#jot-category").val()); - if( !isFinal) { - postSaveTimer = setTimeout(postSaveChanges,10000); - } + if({{$auto_save_draft}}) { + localStorage.setItem("post_title", $("#jot-title").val()); + localStorage.setItem("post_body", $("#profile-jot-text").val()); + localStorage.setItem("post_category", $("#jot-category").val()); + if( !isFinal) { + postSaveTimer = setTimeout(postSaveChanges,10000); + } + } } $(document).ready(function() { - var postTitle = localStorage.getItem("post_title"); - var postBody = localStorage.getItem("post_body"); - var postCategory = localStorage.getItem("post_category"); - var openEditor = false; - if(postTitle) { - $('#jot-title').val(postTitle); - openEditor = true; - } - if(postBody) { - $('#profile-jot-text').val(postBody); - openEditor = true; - } - if(postCategory) { - var categories = postCategory.split(','); - categories.forEach(function(cat) { - $('#jot-category').tagsinput('add', cat); - }); - openEditor = true; - } - if(openEditor) { - initEditor(); + if({{$auto_save_draft}}) { + var postTitle = localStorage.getItem("post_title"); + var postBody = localStorage.getItem("post_body"); + var postCategory = localStorage.getItem("post_category"); + var openEditor = false; + if(postTitle) { + $('#jot-title').val(postTitle); + openEditor = true; + } + if(postBody) { + $('#profile-jot-text').val(postBody); + openEditor = true; + } + if(postCategory) { + var categories = postCategory.split(','); + categories.forEach(function(cat) { + $('#jot-category').tagsinput('add', cat); + }); + openEditor = true; + } + if(openEditor) { + initEditor(); + } + } else { + localStorage.removeItem("post_title"); + localStorage.removeItem("post_body"); + localStorage.removeItem("post_category"); } }); -- cgit v1.2.3