Merge pull request #1051 from anaqreon/auto-save
Auto-save comment and post text
This commit is contained in:
commit
9dc831f1ef
@ -734,6 +734,8 @@ class ThreadItem {
|
|||||||
call_hooks('comment_buttons',$arr);
|
call_hooks('comment_buttons',$arr);
|
||||||
$comment_buttons = $arr['comment_buttons'];
|
$comment_buttons = $arr['comment_buttons'];
|
||||||
|
|
||||||
|
$feature_auto_save_draft = ((feature_enabled($conv->get_profile_owner(), 'auto_save_draft')) ? "true" : "false");
|
||||||
|
|
||||||
$comment_box = replace_macros($template,array(
|
$comment_box = replace_macros($template,array(
|
||||||
'$return_path' => '',
|
'$return_path' => '',
|
||||||
'$threaded' => $this->is_threaded(),
|
'$threaded' => $this->is_threaded(),
|
||||||
@ -768,7 +770,8 @@ class ThreadItem {
|
|||||||
'$anoncomments' => ((($conv->get_mode() === 'channel' || $conv->get_mode() === 'display') && perm_is_allowed($conv->get_profile_owner(),'','post_comments')) ? true : false),
|
'$anoncomments' => ((($conv->get_mode() === 'channel' || $conv->get_mode() === 'display') && perm_is_allowed($conv->get_profile_owner(),'','post_comments')) ? true : false),
|
||||||
'$anonname' => [ 'anonname', t('Your full name (required)') ],
|
'$anonname' => [ 'anonname', t('Your full name (required)') ],
|
||||||
'$anonmail' => [ 'anonmail', t('Your email address (required)') ],
|
'$anonmail' => [ 'anonmail', t('Your email address (required)') ],
|
||||||
'$anonurl' => [ 'anonurl', t('Your website URL (optional)') ]
|
'$anonurl' => [ 'anonurl', t('Your website URL (optional)') ],
|
||||||
|
'$auto_save_draft' => $feature_auto_save_draft,
|
||||||
));
|
));
|
||||||
|
|
||||||
return $comment_box;
|
return $comment_box;
|
||||||
|
@ -1302,6 +1302,8 @@ function status_editor($a, $x, $popup = false) {
|
|||||||
|
|
||||||
$webpage = ((x($x,'webpage')) ? $x['webpage'] : '');
|
$webpage = ((x($x,'webpage')) ? $x['webpage'] : '');
|
||||||
|
|
||||||
|
$feature_auto_save_draft = ((feature_enabled($x['profile_uid'], 'auto_save_draft')) ? "true" : "false");
|
||||||
|
|
||||||
$tpl = get_markup_template('jot-header.tpl');
|
$tpl = get_markup_template('jot-header.tpl');
|
||||||
|
|
||||||
App::$page['htmlhead'] .= replace_macros($tpl, array(
|
App::$page['htmlhead'] .= replace_macros($tpl, array(
|
||||||
@ -1323,6 +1325,7 @@ function status_editor($a, $x, $popup = false) {
|
|||||||
'$modalerroralbum' => t('Error getting album'),
|
'$modalerroralbum' => t('Error getting album'),
|
||||||
'$nocomment_enabled' => t('Comments enabled'),
|
'$nocomment_enabled' => t('Comments enabled'),
|
||||||
'$nocomment_disabled' => t('Comments disabled'),
|
'$nocomment_disabled' => t('Comments disabled'),
|
||||||
|
'$auto_save_draft' => $feature_auto_save_draft,
|
||||||
));
|
));
|
||||||
|
|
||||||
$tpl = get_markup_template('jot.tpl');
|
$tpl = get_markup_template('jot.tpl');
|
||||||
|
@ -350,6 +350,15 @@ function get_features($filtered = true, $level = (-1)) {
|
|||||||
feature_level('suppress_duplicates',1),
|
feature_level('suppress_duplicates',1),
|
||||||
],
|
],
|
||||||
|
|
||||||
|
[
|
||||||
|
'auto_save_draft',
|
||||||
|
t('Auto-save drafts of posts and comments'),
|
||||||
|
t('Automatically saves post and comment drafts in local browser storage to help prevent accidental loss of compositions'),
|
||||||
|
true,
|
||||||
|
get_config('feature_lock','auto_save_draft'),
|
||||||
|
feature_level('auto_save_draft',1),
|
||||||
|
],
|
||||||
|
|
||||||
],
|
],
|
||||||
|
|
||||||
// Network Tools
|
// Network Tools
|
||||||
|
@ -166,6 +166,16 @@ function handle_comment_form(e) {
|
|||||||
$('#' + commentElm).addClass('expanded').removeAttr('placeholder');
|
$('#' + commentElm).addClass('expanded').removeAttr('placeholder');
|
||||||
$('#' + commentElm).attr('tabindex','9');
|
$('#' + commentElm).attr('tabindex','9');
|
||||||
$('#' + submitElm).attr('tabindex','10');
|
$('#' + 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();
|
form.find(':not(:visible)').show();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -185,6 +195,30 @@ function handle_comment_form(e) {
|
|||||||
form.find(':not(.comment-edit-text)').hide();
|
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) {
|
function commentClose(obj, id) {
|
||||||
@ -1106,6 +1140,7 @@ function post_comment(id) {
|
|||||||
$("#comment-edit-form-" + id).serialize(),
|
$("#comment-edit-form-" + id).serialize(),
|
||||||
function(data) {
|
function(data) {
|
||||||
if(data.success) {
|
if(data.success) {
|
||||||
|
localStorage.removeItem("comment_body");
|
||||||
$("#comment-edit-preview-" + id).hide();
|
$("#comment-edit-preview-" + id).hide();
|
||||||
$("#comment-edit-wrapper-" + id).hide();
|
$("#comment-edit-wrapper-" + id).hide();
|
||||||
$("#comment-edit-text-" + id).val('');
|
$("#comment-edit-text-" + id).val('');
|
||||||
|
@ -1,3 +1,6 @@
|
|||||||
|
<script>
|
||||||
|
var auto_save_draft = {{$auto_save_draft}};
|
||||||
|
</script>
|
||||||
{{if $threaded}}
|
{{if $threaded}}
|
||||||
<div class="comment-wwedit-wrapper threaded" id="comment-edit-wrapper-{{$id}}" style="display: block;">
|
<div class="comment-wwedit-wrapper threaded" id="comment-edit-wrapper-{{$id}}" style="display: block;">
|
||||||
{{else}}
|
{{else}}
|
||||||
|
@ -560,3 +560,66 @@ $( document ).on( "click", ".wall-item-delete-link,.page-delete-link,.layout-del
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
</script>
|
</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>
|
Reference in New Issue
Block a user