aboutsummaryrefslogtreecommitdiffstats
path: root/view
diff options
context:
space:
mode:
authorgit-marijus <mario@mariovavti.com>2018-04-09 13:18:09 +0200
committerGitHub <noreply@github.com>2018-04-09 13:18:09 +0200
commit9dc831f1ef5e59a91eeda2756842b7ac262e1ac6 (patch)
tree08faa8318ab53966279b6de5f3fb51dd595f6aac /view
parent6844d7c752a0d8614aa7490287d72a84a95b3a73 (diff)
parentf9ec3c66ff1305ca0647454d27793ac5365f7f4a (diff)
downloadvolse-hubzilla-9dc831f1ef5e59a91eeda2756842b7ac262e1ac6.tar.gz
volse-hubzilla-9dc831f1ef5e59a91eeda2756842b7ac262e1ac6.tar.bz2
volse-hubzilla-9dc831f1ef5e59a91eeda2756842b7ac262e1ac6.zip
Merge pull request #1051 from anaqreon/auto-save
Auto-save comment and post text
Diffstat (limited to 'view')
-rw-r--r--view/js/main.js35
-rwxr-xr-xview/tpl/comment_item.tpl3
-rwxr-xr-xview/tpl/jot-header.tpl63
3 files changed, 101 insertions, 0 deletions
diff --git a/view/js/main.js b/view/js/main.js
index e700c4e6e..c3c2c850f 100644
--- a/view/js/main.js
+++ b/view/js/main.js
@@ -166,6 +166,16 @@ function handle_comment_form(e) {
$('#' + commentElm).addClass('expanded').removeAttr('placeholder');
$('#' + commentElm).attr('tabindex','9');
$('#' + submitElm).attr('tabindex','10');
+
+ 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();
}
@@ -185,6 +195,30 @@ function handle_comment_form(e) {
form.find(':not(.comment-edit-text)').hide();
}
});
+
+ var commentSaveTimer = null;
+ var emptyCommentElm = form.find('.comment-edit-text').attr('id');
+ $(document).on('focusout','#' + emptyCommentElm,function(e){
+ if(commentSaveTimer)
+ clearTimeout(commentSaveTimer);
+ commentSaveChanges(true);
+ commentSaveTimer = null;
+ });
+
+ $(document).on('focusin','#' + emptyCommentElm,function(e){
+ commentSaveTimer = setTimeout(function () {
+ commentSaveChanges(false);
+ },10000);
+ });
+
+ function commentSaveChanges(isFinal = false) {
+ if(auto_save_draft) {
+ localStorage.setItem("comment_body", $('#' + emptyCommentElm).val());
+ if( !isFinal) {
+ commentSaveTimer = setTimeout(commentSaveChanges,10000);
+ }
+ }
+ }
}
function commentClose(obj, id) {
@@ -1106,6 +1140,7 @@ function post_comment(id) {
$("#comment-edit-form-" + id).serialize(),
function(data) {
if(data.success) {
+ localStorage.removeItem("comment_body");
$("#comment-edit-preview-" + id).hide();
$("#comment-edit-wrapper-" + id).hide();
$("#comment-edit-text-" + id).val('');
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 c1dab52d5..7af344681 100755
--- a/view/tpl/jot-header.tpl
+++ b/view/tpl/jot-header.tpl
@@ -560,3 +560,66 @@ $( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-del
}
});
</script>
+
+
+<script>
+
+ var postSaveTimer = null;
+
+ $(document).on('focusout',"#profile-jot-wrapper",function(e){
+ if(postSaveTimer)
+ clearTimeout(postSaveTimer);
+ postSaveChanges(true);
+ postSaveTimer = null;
+ });
+
+ $(document).on('focusin',"#profile-jot-wrapper",function(e){
+ postSaveTimer = setTimeout(function () {
+ postSaveChanges(false);
+ },10000);
+ });
+
+ function postSaveChanges(isFinal = false, type) {
+ 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() {
+ 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");
+ }
+ });
+
+</script> \ No newline at end of file