diff options
-rw-r--r-- | Zotlabs/Lib/ThreadItem.php | 5 | ||||
-rw-r--r-- | include/conversation.php | 5 | ||||
-rw-r--r-- | include/features.php | 9 | ||||
-rw-r--r-- | view/js/main.js | 20 | ||||
-rwxr-xr-x | view/tpl/comment_item.tpl | 3 | ||||
-rwxr-xr-x | view/tpl/jot-header.tpl | 62 |
6 files changed, 68 insertions, 36 deletions
diff --git a/Zotlabs/Lib/ThreadItem.php b/Zotlabs/Lib/ThreadItem.php index d35d4732a..c2aa920b9 100644 --- a/Zotlabs/Lib/ThreadItem.php +++ b/Zotlabs/Lib/ThreadItem.php @@ -733,6 +733,8 @@ class ThreadItem { $arr = array('comment_buttons' => '','id' => $this->get_id()); call_hooks('comment_buttons',$arr); $comment_buttons = $arr['comment_buttons']; + + $feature_auto_save_draft = ((feature_enabled($conv->get_profile_owner(), 'auto_save_draft')) ? "true" : "false"); $comment_box = replace_macros($template,array( '$return_path' => '', @@ -768,7 +770,8 @@ class ThreadItem { '$anoncomments' => ((($conv->get_mode() === 'channel' || $conv->get_mode() === 'display') && perm_is_allowed($conv->get_profile_owner(),'','post_comments')) ? true : false), '$anonname' => [ 'anonname', t('Your full name (required)') ], '$anonmail' => [ 'anonmail', t('Your email address (required)') ], - '$anonurl' => [ 'anonurl', t('Your website URL (optional)') ] + '$anonurl' => [ 'anonurl', t('Your website URL (optional)') ], + '$auto_save_draft' => $feature_auto_save_draft, )); return $comment_box; diff --git a/include/conversation.php b/include/conversation.php index ce0467770..3834d9866 100644 --- a/include/conversation.php +++ b/include/conversation.php @@ -1301,7 +1301,9 @@ function status_editor($a, $x, $popup = false) { $id_select = ''; $webpage = ((x($x,'webpage')) ? $x['webpage'] : ''); - + + $feature_auto_save_draft = ((feature_enabled($x['profile_uid'], 'auto_save_draft')) ? "true" : "false"); + $tpl = get_markup_template('jot-header.tpl'); App::$page['htmlhead'] .= replace_macros($tpl, array( @@ -1323,6 +1325,7 @@ function status_editor($a, $x, $popup = false) { '$modalerroralbum' => t('Error getting album'), '$nocomment_enabled' => t('Comments enabled'), '$nocomment_disabled' => t('Comments disabled'), + '$auto_save_draft' => $feature_auto_save_draft, )); $tpl = get_markup_template('jot.tpl'); diff --git a/include/features.php b/include/features.php index 4859a01db..36f4f0433 100644 --- a/include/features.php +++ b/include/features.php @@ -350,6 +350,15 @@ function get_features($filtered = true) { feature_level('suppress_duplicates',1), ], + [ + 'auto_save_draft', + t('Auto-save drafts of posts and comments'), + t('Automatically saves post and comment drafts in local browser storage to help prevent accidental loss of compositions'), + true, + get_config('feature_lock','auto_save_draft'), + feature_level('auto_save_draft',1), + ], + ], // Network Tools 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 @@ + <script> + var auto_save_draft = {{$auto_save_draft}}; + </script> {{if $threaded}} <div class="comment-wwedit-wrapper threaded" id="comment-edit-wrapper-{{$id}}" style="display: block;"> {{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"); } }); |