diff options
Diffstat (limited to 'view/tpl/jot-header.tpl')
-rwxr-xr-x | view/tpl/jot-header.tpl | 88 |
1 files changed, 88 insertions, 0 deletions
diff --git a/view/tpl/jot-header.tpl b/view/tpl/jot-header.tpl index c1dab52d5..991a4c8b1 100755 --- a/view/tpl/jot-header.tpl +++ b/view/tpl/jot-header.tpl @@ -560,3 +560,91 @@ $( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-del } }); </script> + + +<script> + var postSaveTimer = null; + + function postSaveChanges(action, type) { + if({{$auto_save_draft}}) { + + if(action != 'clean') { + localStorage.setItem("post_title", $("#jot-title").val()); + localStorage.setItem("post_body", $("#profile-jot-text").val()); + if($("#jot-category").length) + localStorage.setItem("post_category", $("#jot-category").val()); + } + + if(action == 'start') { + postSaveTimer = setTimeout(function () { + postSaveChanges('start'); + },10000); + } + + if(action == 'stop') { + clearTimeout(postSaveTimer); + postSaveTimer = null; + } + + if(action == 'clean') { + clearTimeout(postSaveTimer); + postSaveTimer = null; + localStorage.removeItem("post_title"); + localStorage.removeItem("post_body"); + localStorage.removeItem("post_category"); + } + } + + } + + $(document).ready(function() { + + var cleaned = false; + + if({{$auto_save_draft}}) { + var postTitle = localStorage.getItem("post_title"); + var postBody = localStorage.getItem("post_body"); + var postCategory = (($("#jot-category").length) ? 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 { + postSaveChanges('clean'); + } + + $(document).on('submit', '#profile-jot-form', function() { + postSaveChanges('clean'); + cleaned = true; + }); + + $(document).on('focusout',"#profile-jot-wrapper",function(e){ + if(! cleaned) + postSaveChanges('stop'); + }); + + $(document).on('focusin',"#profile-jot-wrapper",function(e){ + postSaveTimer = setTimeout(function () { + postSaveChanges('start'); + },10000); + }); + + + }); +</script> |