From b0396cd646040facbe719d08183d326ccba1b53f Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 12 Apr 2018 21:44:06 -0700 Subject: work on autosave --- view/js/main.js | 45 ++++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) (limited to 'view') diff --git a/view/js/main.js b/view/js/main.js index 02f2f6a3d..66a1452e3 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -168,15 +168,6 @@ function handle_comment_form(e) { $('#' + 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(); } @@ -199,24 +190,25 @@ function handle_comment_form(e) { var commentSaveTimer = null; var emptyCommentElm = form.find('.comment-edit-text').attr('id'); + var convId = emptyCommentElm.replace(/comment-edit-text-/,''); $(document).on('focusout','#' + emptyCommentElm,function(e){ if(commentSaveTimer) clearTimeout(commentSaveTimer); - commentSaveChanges(true); + commentSaveChanges(convId,true); commentSaveTimer = null; }); $(document).on('focusin','#' + emptyCommentElm,function(e){ commentSaveTimer = setTimeout(function () { - commentSaveChanges(false); + commentSaveChanges(convId,false); },10000); }); - function commentSaveChanges(isFinal = false) { + function commentSaveChanges(convId,isFinal = false) { if(auto_save_draft) { - localStorage.setItem("comment_body", $('#' + emptyCommentElm).val()); + localStorage.setItem("comment_body" + convId, $('#' + emptyCommentElm).val()); if( !isFinal) { - commentSaveTimer = setTimeout(commentSaveChanges,10000); + commentSaveTimer = setTimeout(commentSaveChanges,10000,convId); } } } @@ -600,8 +592,12 @@ function updateConvItems(mode,data) { $('.thread-wrapper.toplevel_item',data).each(function() { var ident = $(this).attr('id'); - + var convId = ident.replace('thread-wrapper-',''); var commentWrap = $('#'+ident+' .collapsed-comments').attr('id'); + + + + var itmId = 0; var isVisible = false; @@ -612,6 +608,9 @@ function updateConvItems(mode,data) { if($('#collapsed-comments-'+itmId).is(':visible')) isVisible = true; + + + // insert the content according to the mode and first_page // and whether or not the content exists already (overwrite it) @@ -633,6 +632,22 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); + var commentBody = localStorage.getItem("comment_body" + convId); + + if(commentBody) { + var commentElm = $('#comment-edit-text' + convId); + if(auto_save_draft) { + if(commentBody && $('#' + commentElm).val() === '') { + $('#comment-edit-form-' + convId).show(); + $('#' + commentElm).val(commentBody); + } + } else { + localStorage.removeItem("comment_body" + convId); + } + } + + + // trigger the autotime function on all newly created content $("> .wall-item-outside-wrapper .autotime, > .thread-wrapper .autotime",this).timeago(); -- cgit v1.2.3 From 7fd882a088b55ccbe16b3f9cc076f916ddb90341 Mon Sep 17 00:00:00 2001 From: zotlabs Date: Thu, 12 Apr 2018 22:24:25 -0700 Subject: autosave comment enhancements --- view/js/main.js | 24 +++++++++++++++--------- 1 file changed, 15 insertions(+), 9 deletions(-) (limited to 'view') diff --git a/view/js/main.js b/view/js/main.js index 66a1452e3..c1e7bd4ec 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -190,7 +190,7 @@ function handle_comment_form(e) { var commentSaveTimer = null; var emptyCommentElm = form.find('.comment-edit-text').attr('id'); - var convId = emptyCommentElm.replace(/comment-edit-text-/,''); + var convId = emptyCommentElm.replace('comment-edit-text-',''); $(document).on('focusout','#' + emptyCommentElm,function(e){ if(commentSaveTimer) clearTimeout(commentSaveTimer); @@ -206,7 +206,13 @@ function handle_comment_form(e) { function commentSaveChanges(convId,isFinal = false) { if(auto_save_draft) { - localStorage.setItem("comment_body" + convId, $('#' + emptyCommentElm).val()); + tmp = $('#' + emptyCommentElm).val(); + if(tmp) { + localStorage.setItem("comment_body-" + convId, tmp); + } + else { + localStorage.removeItem("comment_body-" + convId); + } if( !isFinal) { commentSaveTimer = setTimeout(commentSaveChanges,10000,convId); } @@ -596,8 +602,6 @@ function updateConvItems(mode,data) { var commentWrap = $('#'+ident+' .collapsed-comments').attr('id'); - - var itmId = 0; var isVisible = false; @@ -632,17 +636,19 @@ function updateConvItems(mode,data) { if(isVisible) showHideComments(itmId); - var commentBody = localStorage.getItem("comment_body" + convId); + var commentBody = localStorage.getItem("comment_body-" + convId); if(commentBody) { - var commentElm = $('#comment-edit-text' + convId); + var commentElm = $('#comment-edit-text-' + convId); if(auto_save_draft) { - if(commentBody && $('#' + commentElm).val() === '') { + if($(commentElm).val() === '') { $('#comment-edit-form-' + convId).show(); - $('#' + commentElm).val(commentBody); + $(commentElm).addClass("expanded"); + openMenu("comment-tools-" + convId); + $(commentElm).val(commentBody); } } else { - localStorage.removeItem("comment_body" + convId); + localStorage.removeItem("comment_body-" + convId); } } -- cgit v1.2.3