diff options
author | Andrew Manning <tamanning@zoho.com> | 2018-04-08 14:18:10 -0400 |
---|---|---|
committer | Andrew Manning <tamanning@zoho.com> | 2018-04-08 14:18:10 -0400 |
commit | 43cafcc761bc12f442c30ab952164736aa18f9d8 (patch) | |
tree | 52a890ff54a9a413460c38b61833139639e6d341 /view/js | |
parent | be6dcb5d0a96d3618c4d4d824bf94b0a6753fefc (diff) | |
download | volse-hubzilla-43cafcc761bc12f442c30ab952164736aa18f9d8.tar.gz volse-hubzilla-43cafcc761bc12f442c30ab952164736aa18f9d8.tar.bz2 volse-hubzilla-43cafcc761bc12f442c30ab952164736aa18f9d8.zip |
Auto-save post and comment entry using localStorage in browser.
Diffstat (limited to 'view/js')
-rw-r--r-- | view/js/main.js | 29 |
1 files changed, 29 insertions, 0 deletions
diff --git a/view/js/main.js b/view/js/main.js index e700c4e6e..d09615f3c 100644 --- a/view/js/main.js +++ b/view/js/main.js @@ -166,6 +166,12 @@ function handle_comment_form(e) { $('#' + commentElm).addClass('expanded').removeAttr('placeholder'); $('#' + commentElm).attr('tabindex','9'); $('#' + submitElm).attr('tabindex','10'); + + var commentBody = localStorage.getItem("comment_body"); + if(commentBody && $('#' + commentElm).val() === '') { + $('#' + commentElm).val(commentBody); + } + form.find(':not(:visible)').show(); } @@ -185,6 +191,28 @@ 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, type) { + localStorage.setItem("comment_body", $('#' + emptyCommentElm).val()); + if( !isFinal) { + commentSaveTimer = setTimeout(commentSaveChanges,10000); + } + } } function commentClose(obj, id) { @@ -1106,6 +1134,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(''); |