diff options
-rw-r--r-- | Zotlabs/Module/Autosavetext.php | 37 | ||||
-rw-r--r-- | view/js/main.js | 29 | ||||
-rwxr-xr-x | view/tpl/jot-header.tpl | 55 |
3 files changed, 121 insertions, 0 deletions
diff --git a/Zotlabs/Module/Autosavetext.php b/Zotlabs/Module/Autosavetext.php new file mode 100644 index 000000000..f6bffd2a2 --- /dev/null +++ b/Zotlabs/Module/Autosavetext.php @@ -0,0 +1,37 @@ +<?php +namespace Zotlabs\Module; /** @file */ + + +class Autosavetext extends \Zotlabs\Web\Controller { + + function init() { + + if(! local_channel()) + return; + + $ret = array('success' => true); + if(array_key_exists('body',$_REQUEST) && array_key_exists('type',$_REQUEST)) { + $body = escape_tags($_REQUEST['body']); + $title = (array_key_exists('title',$_REQUEST) ? escape_tags($_REQUEST['title']) : ''); + $type = $_REQUEST['type']; + + if($body && $type === 'post') { + set_pconfig(local_channel(),'autosavetext_post','body',$body); + set_pconfig(local_channel(),'autosavetext_post','title',$title); + } + + logger('post saved.', LOGGER_DEBUG); + } + + // // push updates to channel clones + // + // if((argc() > 1) && (argv(1) === 'sync')) { + // require_once('include/zot.php'); + // build_sync_packet(); + // } + + json_return_and_die($ret); + + } + +} 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(''); diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index c1dab52d5..2b4284ade 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -560,3 +560,58 @@ $( 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) { + 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(); + } + }); + +</script>
\ No newline at end of file |